c++ - 如何使用 pack 作为模板参数实例化专门的模板类?

标签 c++ templates

我从 Template with Multiple pack as input parameter 中获取了以下示例.

#include <iostream>
#include <tuple>

// A template to hold a parameter pack.                                                                                                                                                                                                                                                                                                                                                       
template < typename... >
struct Typelist {};

// Declaration of a template with multiple parameter pack.                                                                                                                                                                                                                                                                                                                                    
template< typename TypeListOne                                                                                                                                                                                                                                                                                                                                                                
        , typename TypeListTwo                                                                                                                                                                                                                                                                                                                                                                
        >                                                                                                                                                                                                                                                                                                                                                                                     
struct SomeStruct;

// Specialization of template with multiple parameter packs                                                                                                                                                                                                                                                                                                                                   
template< typename... TypesOne
        , typename... TypesTwo
        >
struct SomeStruct< Typelist < TypesOne... >
                 , Typelist < TypesTwo... >
                 >
{
    // Can use TypesOne... and TypesTwo... how ever                                                                                                                                                                                                                                                                                                                                           
    // you want here. For example:                                                                                                                                                                                                                                                                                                                                                            
    typedef std::tuple< TypesOne... > TupleTypeOne;
    typedef std::tuple< TypesTwo... > TupleTypeTwo;
};

我想知道如何实例化 SomeStruct 的对象。

最佳答案

例如:

SomeStruct <Typelist <char, int, char>,
            Typelist <int, double>> var;

关于c++ - 如何使用 pack 作为模板参数实例化专门的模板类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55308356/

相关文章:

c++ - 我如何在 C++ (C++0x) 中使用 'auto'?

c++ - C++模板特化和函数返回值

templates - 使用数组将MapResult转换为数组

c++ - 使用 C++ 标准库转换 UTF-8 (no/clr)

c++ - 使用 patchelf 和备用 glibc 版本时找不到 libstdc++.so

c++ - C++ 中的随机段错误

c++ - 通过添加一些特殊字符使/* 的含义用于取消引用和划分不用于注释

c++ - 使用模板制作类型安全的 C++ "component manager"

c++ - 无法分配一个指向模板化类的指针的成员

javascript - 我可以通过引用不存在的内容来使 Ember 模板构建失败吗?