fork download
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. //A type trait for a vector
  5. template <typename T> struct Is_Vector { static const bool value = false; };
  6. template <typename T> struct Is_Vector<std::vector<T>> { static const bool value = true; };
  7.  
  8.  
  9. // A function that identifies whether the argument is a vector or not
  10. template <typename Type>
  11. bool isVector(Type object){
  12. return Is_Vector<Type>::value;
  13. }
  14.  
  15. int main() {
  16.  
  17.  
  18. std::vector<int> vector;
  19. int integer;
  20.  
  21. std::cout << std::boolalpha;
  22. std::cout << isVector(vector) << '\n';
  23. std::cout << isVector(integer) << '\n';
  24.  
  25. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
true
false