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

时间:2017-04-09 08:35:55

标签: 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>>;
                                      ^

1 个答案:

答案 0 :(得分:2)

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

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