specializzazione parziale per quando si vuole consentire a qualsiasi confronto, Hasher,-uguale-comparatore chiave e allocatore:
template<class Comp, class Alloc>
struct check<std::map<std::string, std::string, Comp, Alloc>>{
static const bool value = true;
};
template<class Hash, class KeyEq, class Alloc>
struct check<std::unordered_map<std::string, std::string, Hash, KeyEq, Alloc>>{
static const bool value = true;
};
Se si vuole verificare se T
utilizzato la versione predefinita di quei tipi (aka solo map<A,B>
e non map<A,B,my_comp>
, è possibile omettere gli argomenti del modello e andare con specializzazione esplicita:
template<>
struct check<std::map<std::string, std::string>>{
static const bool value = true;
};
template<>
struct check<std::unordered_map<std::string, std::string>>{
static const bool value = true;
};
E se si desidera controllare in generale, se si tratta di un std::map
o std::unordered_map
di qualsiasi combinazione chiave/valore (e di confronto/Hasher/ecc), si può andare completamente generico preso dal here:
#include <type_traits>
template < template <typename...> class Template, typename T >
struct is_specialization_of : std::false_type {};
template < template <typename...> class Template, typename... Args >
struct is_specialization_of< Template, Template<Args...> > : std::true_type {};
template<class A, class B>
struct or_ : std::integral_constant<bool, A::value || B::value>{};
template<class T>
struct check
: or_<is_specialization_of<std::map, T>,
is_specialization_of<std::unordered_map, T>>{};