【问题标题】:Error when not specify template arguments for alias template declared with default template arguments未为使用默认模板参数声明的别名模板指定模板参数时出错
【发布时间】:2017-04-09 08:35:55
【问题描述】:

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

基础存储类:

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>>;
                                      ^

【问题讨论】:

  • 对不起,我忘记了存储模板!反正main是空的,把using放在里面就行了。
  • 嗯,情况发生了很大变化。谢谢。

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


【解决方案1】:

type 被声明为别名模板,则此处需要模板参数。因为声明了默认参数,所以只需为其添加&lt;&gt;,例如

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

【讨论】:

  • 我的错,我希望编译器为我这样做似乎......谢谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-09
  • 2016-10-06
  • 2015-08-15
  • 2017-04-15
相关资源
最近更新 更多