c++ - 未为使用默认模板参数声明的别名模板指定模板参数时出错

标签 c++ c++11 templates metaprogramming template-meta-programming

我试图让用户生成他们自己的存储类型,但我迷失了最后一个模板元函数。

基本存储类:

template < typename Data,
           typename P1,
           typename P2,
           typename P3 >
struct Storage : P1, P2, P3 {};

元函数:

template < template <typename,typename> typename Container,
           template <typename...> typename WrapperType,
           template <typename> typename Allocator = std::allocator >
struct MetaStorage {

  template < template <typename> typename P1,
             template <typename> typename P2,
             template <typename> typename P3 >
  struct With_Policies {

    template < typename ... Ts >
    struct With_Types {

      template < typename T = WrapperType<Ts...>,
                 typename Data = Container<T, Allocator<T>> >
      using type = Storage<Data,
                           P1<Data>,
                           P2<Data>,
                           P3<Data>>;
    };
  };
};

用例:

template <typename ... T > struct DefaultWrapper {};

template < typename T > struct Policie1 {};
template < typename T > struct Policie3 {};
template < typename T > struct Policie2 {};

struct C1 {};
struct C2 {};

using Sig = MetaStorage<std::vector, DefaultWrapper>::With_Policies<Policie1, Policie2, Policie3>::With_Types<C1, C2>::type;

错误 g++ 6.3:

test.cpp: In function ‘int main()’: test.cpp:137:15: error: invalid  use of template-name ‘MetaStorage<std::vector,  DefaultWrapper>::With_Policies<Policie1, Policie2,  Policie3>::With_Types<C1, C2>::type’ without an argument list    using Sig = MetaStorage<std::vector,  DefaultWrapper>::With_Policies<Policie1, Policie2,  Policie3>::With_Types<C1, C2>::type;
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test.cpp:58:37: note: ‘template<class T, class Data> using type =  Storage<Data, Policie1<Data>, Policie2<Data>, Policie3<Data> >’  declared here
                             P3<Data>>;
                                      ^

最佳答案

type被声明为别名模板,那么这里需要模板参数。因为声明了默认参数,所以只需添加 <>为此,例如

using Sig = MetaStorage<std::vector, DefaultWrapper>::With_Policies<Policie1, Policie2, Policie3>::With_Types<C1, C2>::type<>;
//                                                                                                                         ~~

关于c++ - 未为使用默认模板参数声明的别名模板指定模板参数时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43304715/

相关文章:

c++ - 从函数返回迭代器给我一个奇怪的错误

c++ - 存在冲突符号时使用一个或多个命名空间?

c++ - 第一次使用STM upsd3200系列单片机

c++ - 检查类是否具有给定签名的成员函数

C++17 if constexpr() 与元组一起使用

c++ - 多线程中的同步

c++ - 如何简洁地将默认构造的对象插入 std::vector

c++ - 重载 [] 和 , c++11

c++ - 如何访问可变成员?

c++ - std::max,但用于模板参数