I have a templated class, that can have a map type as template parameter.
template<typename map_t> class my_class
{
map_t my_map;
};
Now I'd like the value type of the map, to be equal to this class.
my_class<std::map<std::string, my_class<...> > > problems;
However, this is impossible to declare. How can I achieve the same effect?
Since you want to be generic in the container type, the closest I have been able to find (if I understand well your intent) is:
template <template <typename, typename> class Map>
struct my_class
{
typedef typename Map<std::string, my_class>::type map_t;
map_t children;
};
// Since the standard doesn't allow default arguments to be
// taken into account for template template parameters, we
// have to close them.
// Write one such structure for each map type you want.
struct std_map
{
template <typename Key, typename Value>
struct rebind { typedef std::map<Key, Value> type; }
};
and use
my_class<std_map::rebind> problematic_tree;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With