In C++11 you can also do it in a more generic way:
#include <type_traits>
#include <iostream>
#include <vector>
#include <list>
template<typename Test, template<typename...> class Ref>
struct is_specialization : std::false_type {};
template<template<typename...> class Ref, typename... Args>
struct is_specialization<Ref<Args...>, Ref>: std::true_type {};
int main()
{
typedef std::vector<int> vec;
typedef int not_vec;
std::cout << is_specialization<vec, std::vector>::value << is_specialization<not_vec, std::vector>::value;
typedef std::list<int> lst;
typedef int not_lst;
std::cout << is_specialization<lst, std::list>::value << is_specialization<not_lst, std::list>::value;
}
typedef
)? Or a specialized implementation for a certain type (likestd::vector<bool>
is)? – Some programmer dudestd::vector
for a type, you shouldn't be able to do it (not in a clean way anyway). If you want to determine if a type is inherited from std::vector<XXX>, this is explicitly advised against (std::vector doesn't have a virtual destructor and SHOULD NOT be inherited, only encapsulated). If you want to determine if a class/typedef/template parameter is a std::vector<XYZ, ...>, you should use a templated traits class (see answer from jrok). – utnapistimstruct is_std_vector<std::vector<T,A>>
is a particularized implementation ofstruct is_std_vector
in jirok's answer). Is there a way of doing that? – utnapistim