fork download
  1. #include <iostream>
  2. #include <type_traits>
  3. #include <vector>
  4. #include <list>
  5. using namespace std;
  6.  
  7. template<template<class,class> class C>
  8. struct is_vector1 : std::false_type { };
  9.  
  10. template<>
  11. struct is_vector1<std::vector> : std::true_type { };
  12.  
  13. template<typename T>
  14. struct is_vector2 : false_type { };
  15.  
  16. template<typename E, typename A>
  17. struct is_vector2<vector<E, A>> : true_type { };
  18.  
  19. template<template<class, class> class T>
  20. typename enable_if<!is_vector1<T>::value, char>::type is_vectorf();
  21.  
  22. template<template<class, class> class T>
  23. typename enable_if<is_vector1<T>::value, char(&)[2]>::type is_vectorf();
  24.  
  25. template<typename T>
  26. typename enable_if<!is_vector2<T>::value, char>::type is_vectorf();
  27.  
  28. template<typename T>
  29. typename enable_if<is_vector2<T>::value, char(&)[2]>::type is_vectorf();
  30.  
  31. #define is_vector(T) ::std::integral_constant<bool, sizeof(::is_vectorf<T>()) != 1>
  32.  
  33. int main() {
  34. cout << (is_vector(list)::value ? "is vector\n" : "no vector\n");
  35. cout << (is_vector(vector)::value ? "is vector\n" : "no vector\n");
  36. cout << (is_vector(list<int>)::value ? "is vector\n" : "no vector\n");
  37. cout << (is_vector(vector<int>)::value ? "is vector\n" : "no vector\n");
  38. cout << (is_vector(int)::value ? "is vector\n" : "no vector\n");
  39. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
no vector
is vector
no vector
is vector
no vector