How can I find if a type is an instantiation of a certain template, like say set?

Hi,

Now that we have constexpr if, can we find if a type is the specialization of a certain template (say:

1
2
3
4
5
std::set<int> s;
// or 
std::vector<int> s;

if constexpr ( decltype(s) IS set<T> ) ///// obviously not C++ 


Maybe in the case of containers, they have tags? If so, then we can query what kind of container we have. But I was looking for more deep reflection...


Regards,
Juan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <set>
#include <type_traits>
#include <vector>

template <template <typename...> class, typename>
struct is_instance_of : std::false_type {};
template <template <typename...> class Tm, typename... Ts>
struct is_instance_of<Tm, Tm<Ts...>> : std::true_type {};

template <typename T>
constexpr bool is_instance_of_set = is_instance_of<std::set, T>::value;

static_assert( is_instance_of_set<std::set<int>>);
static_assert(!is_instance_of_set<std::vector<int>>);
Thanks!!

Juan
Topic archived. No new replies allowed.