Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A recursive template type for a container / typename forwarding

Tags:

c++

Is there any way to get a recursive template type? I have a container for which I want to specify an underlying storage strategy. The inner template must however use the outer template's type, so it causes a loop in the type definition -- which isn't possible to specify.

About what I want:

template<typename C>
struct inner {
    C * object[16];
};

template<typename T, typename Inner>
struct container {
    T value;
    Inner<container> holder;
};

C++11 solutions are fine (though I'm still on gcc 4.6.3).

like image 631
edA-qa mort-ora-y Avatar asked Jul 30 '13 12:07

edA-qa mort-ora-y


1 Answers

You need to tell the compiler that Inner is a templated class:

template<typename T, template<typename> class Inner>
struct container {
    T value;
    Inner<container> holder;
};
like image 141
Some programmer dude Avatar answered Oct 13 '22 00:10

Some programmer dude