可变参数模板模板参数接受任何模板:
template<typename T>
struct Test1 {
using type = int;
};
template<typename T, typename T1>
struct Test2 {
using type = char*;
};
template<template<typename...S> class BeCurry>
struct Currying {
};
using curry = Currying<Test1>;
using curry2 = Currying<Test2>;
Run Code Online (Sandbox Code Playgroud)
我想要Currying模板模板类.
这意味着:如果参数接受一个模板参数Test1,curry::apply<T>::type get Test1<T>::type.如果参数接受两个模板参数Test2,curry2::apply<T0>则为"部分"模板,curry2::apply<T0>::apply<T1>::type get Test2<T0,T1>::type
这有可能实现吗?因为我无法查询模板模板参数的内部参数num:
template<template<typename... S> class BeCurry>
struct Currying {
enum { value = sizeof...(S) }; // error!
};
Run Code Online (Sandbox Code Playgroud) 我想将树型扁平化为扁平型.例:
typedef std::tuple<int,std::tuple<int,long>,int> tup;
Flat<tup>::type=>std::tuple<int,int,long,int>
Run Code Online (Sandbox Code Playgroud)
我用:
template<typename T>
struct Flat
{
using type=T;
};
template <template <typename ...> class C,typename...ARGS>
struct Flat<C<ARGS...> >
{
using type=C<ARGS...>;
};
template <template <typename ...> class C,typename ...ARGS0,typename...ARGS1,typename ...ARGS2>
struct Flat<C<ARGS0...,C<ARGS1...>,ARGS2...> >
:Flat<C<ARGS0...,ARGS1...,ARGS2...> >
{
};
void test(){
typedef std::tuple<int,std::tuple<int,long>,int> tup;
static_assert(std::is_same<typename Flat<tup>::type,std::tuple<int,int,long,int> >::value,"");
}
Run Code Online (Sandbox Code Playgroud)
但我std::tuple<int,std::tuple<int,long>,int>还是静止...我使用gcc 4.8.1