fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template<typename C>
  5. struct IsIterable
  6. {
  7. typedef char true_type;
  8. typedef long false_type;
  9.  
  10. template<class T> static true_type is_beg_iterable(int i,
  11. typename T::const_iterator = C().begin());
  12. template<class T> static false_type is_beg_iterable(...);
  13.  
  14. enum { value = sizeof(is_beg_iterable<C>(0)) == sizeof(true_type) };
  15. };
  16.  
  17. int main() {
  18. std::cout << IsIterable<std::vector<int>>::value << std::endl;
  19. std::cout << IsIterable<int>::value << std::endl;
  20. }
  21.  
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
1
0