If I have a templates looking like this that perform a simple operation of copying for the sake of example but for std::map
and std::unordered_map
:
template<typename T1, typename T2>
inline std::map<T1, T2> map_copy(std::map<T1,T2> const& a) {
std::map<T1,T2> output;
output = a;
return output;
}
template<typename T1, typename T2>
inline std::unordered_map<T1, T2> map_copy(std::unordered_map<T1,T2> const& a) {
std::unordered_map<T1,T2> output;
output = a;
return output;
}
Is there a way, probably using C++ concepts, to reduce these definitions to just one, constraining the possible types just to std::map
and std::unordered_map
?
You can use this concept to check if a type is a
std::map
orstd::unordered_map
:For generic checking if
T
is an instantiation oftemplate<typename...> struct Template;
, you could do something like: