Partially default initialize template template parameters with internal type

159 views Asked by At
template <template <typename> class container_type>
class MyClass
{
    class Internal{
    };
};

I want to use this class (or how it would look correctly) in a way like the following...

MyClass(std::list);

...so that in MyClass container_type is declared/typedef'd as:

std::list<Internal*>

Is something like this somehow possible?

1

There are 1 answers

1
Yuushi On BEST ANSWER

You likely want something like the following:

#include <list>
#include <memory>

template <template <typename, typename> 
          class Container = std::list>
class MyClass 
{
    class Internal
    { };

    Container<Internal*, std::allocator<Internal*>> my_list;
};

int main()
{
    MyClass<> m;
}

Here's a compilable example you can play with. Note that both the extra typename and the definition of an allocator is required here.