fork download
  1. #include <type_traits>
  2. #include <list>
  3. #include <vector>
  4. #include <string>
  5.  
  6. template <class T>
  7. struct isSupportedContainer : std::false_type {};
  8.  
  9. template <class T>
  10. struct isSupportedContainer < std::list<T> > : std::true_type {};
  11.  
  12. template <class T>
  13. struct isSupportedContainer < std::vector<T> > : std::true_type {};
  14.  
  15. template <class T, typename = void>
  16. struct isSupported : std::integral_constant<bool, std::is_object<T>::value> {};
  17.  
  18. template <class Cont>
  19. struct isSupported<Cont, typename std::enable_if<isSupportedContainer<Cont>::value>::type> :
  20. std::integral_constant<bool, isSupported<typename Cont::value_type>::value> {};
  21.  
  22.  
  23. int main() {
  24. static_assert(isSupported<std::vector<int>>::value,"");
  25. static_assert(isSupported<std::vector<std::list<int>>>::value,"");
  26. static_assert(isSupported<std::string>::value,"");
  27. static_assert(!isSupported<int&>::value,"");
  28. return 0;
  29. }
Success #stdin #stdout 0s 3408KB
stdin
Standard input is empty
stdout
Standard output is empty