fork download
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. template <typename T>
  7. struct has_const_iterator {
  8. typedef char yes[1];
  9. typedef char no[2];
  10.  
  11. template <typename C> static yes& test(typename C::const_iterator*);
  12. template <typename> static no& test(...);
  13.  
  14. static const bool value = sizeof(test<T>(0)) == sizeof(yes);
  15. };
  16.  
  17. template <bool> class bool2class {};
  18.  
  19. template <class T>
  20. void set_inner(const std::string &path, T & var, bool2class<false> *) {
  21. cout << "Not STL" << endl;
  22. }
  23.  
  24. template <class T>
  25. void set_inner(const std::string &path, T & var, bool2class<true> *) {
  26. cout << "STL" << endl;
  27. }
  28.  
  29. template <class T>
  30. void set(const std::string &path, T &var) {
  31. set_inner(path, var, (bool2class<has_const_iterator<T>::value>*)0);
  32. }
  33.  
  34. int main() {
  35. char a[4];
  36. vector<char> b;
  37. set("a:", a);
  38. set("b: ", b);
  39. }
Success #stdin #stdout 0.02s 2812KB
stdin
Standard input is empty
stdout
Not STL
STL