I've been experimenting with C++ template meta programming. For a particular problem I would like to be able to pass a template as a template argument. As a minimal example, the following works:
template <class T> class H : public T {};
template <template <class> class TT>
class Assembler
{
public:
using Type = TT<void>;
};
template <class T> using Folded = H<H<H<T> > >;
using ThisWorks = Assembler<Folded>::Type;
But, if I don't explicitly fold the other templates my program fails to compile:
using ThisDoesnt = Assembler<H<H<H> > >::Type;
Why does this second form not work (I can take a guess at why it doesn't work, but I would really appreciate a clear explaination)? And, is there another alternative (or a more elegant way) for folding the other templates into a single template type?
Aucun commentaire:
Enregistrer un commentaire