Template-Metaprogrammierung: Warum Flat-Type versagt
Ich möchte einen Baumtyp auf einen flachen Typ reduzieren. Beispiel:
typedef std::tuple<int,std::tuple<int,long>,int> tup;
Flat<tup>::type=>std::tuple<int,int,long,int>
Ich benutze:
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,"");
}
aber ich verstehestd::tuple<int,std::tuple<int,long>,int>
immer noch ... ich benutze gcc 4.8.1