繁体   English   中英

C ++模板模板实例化

[英]C++ Template Template Instantiation

我有以下用于可变参数包的封装代码。

template <typename... Args>
struct pack
{
};

template <template <typename... Args> class ENCAP, typename... Args>
struct encapsulate_arguments
{
    typedef pack<ENCAP<Args>...> type;
};

template <template <typename... Args> class ENCAP, typename... Args>
struct encapsulate_arguments<ENCAP, pack<Args...>>
{
    typedef pack<ENCAP<Args>...> type;
};

template <typename L>   
struct Master
{
    template <typename T>
    struct Slave
    {
        typedef T type; 
    };
};

这适用于封装可变参数包,例如:

typedef encapsulate_arguments<Master<float>::Slave, double, int>::type foo;

要么

typedef encapsulate_arguments<Master<float>::Slave, pack<double, int>>::type foo;

要么

typedef encapsulate_arguments<std::vector, pack<double, int>>::type foo;

它不依赖于另一个模板参数 - 导致定义以下内容:

pack<Master<float>::Slave<double>, Master<float>::Slave<int>>

要么

pack<std::vector<double>, std::vector<int>>

问题是,如果我想使封装模板参数ENCAP类型依赖,我无法编译它:

template <typename L>   
struct Other
{
// ARGGH!!!
//  typedef encapsulate_arguments<Master<L>::Slave, pack<double, int>>::type EmbeddedType;
};

http://ideone.com/ZwfVaU

这是否可能和/或我怎样才能使这项工作?

您缺少typenametemplate

typedef typename encapsulate_arguments<
//      ^^^^^^^^
    Master<L>::template Slave, pack<double, int>
//             ^^^^^^^^
>::type EmbeddedType;

演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM