template<typename T>
struct check
{
static const bool value = false;
};
What I want to do is to have check<T>::value be true if and only if T is a std::map<A,B> or std::unordered_map<A,B> and both A and B be std::string. So basically check enables compile-time checking of the type T.
How do I do this?
Partial specialization for when you want to allow any comparator, hasher, key-equal-comparator and allocator:
If you want to check if
Tused the default version of those types (aka onlymap<A,B>and notmap<A,B,my_comp>, you can omit the template arguments and go with explicit specialization:And if you want to generally check if it’s a
std::maporstd::unordered_mapof any key/value combination (and comparator / hasher / etc.), you can go fully generic as taken from here: