fork download
  1. #include <type_traits>
  2. #include <iterator>
  3. #include <list>
  4. #include <vector>
  5.  
  6. template<typename T, typename = void>
  7. struct is_const_iterator : std::false_type { };
  8.  
  9. template<typename T>
  10. struct is_const_iterator<T,
  11. typename std::enable_if<
  12. std::is_const<
  13. typename std::remove_pointer<
  14. typename std::iterator_traits<T>::pointer
  15. >::type
  16. >::value
  17. >::type> : std::true_type { };
  18.  
  19. int main()
  20. {
  21. typedef std::list<int>::iterator LI;
  22. typedef std::list<int>::const_iterator CLI;
  23. static_assert(is_const_iterator<LI>::value, "!"); // Fires
  24. static_assert(is_const_iterator<CLI>::value, "!"); // Does not fire
  25.  
  26. typedef std::vector<int>::iterator VI;
  27. typedef std::vector<int>::const_iterator CVI;
  28. static_assert(is_const_iterator<VI>::value, "!"); // Fires
  29. static_assert(is_const_iterator<CVI>::value, "!"); // Does not fire
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:23:9: error: static assertion failed: !
prog.cpp:28:9: error: static assertion failed: !
stdout
Standard output is empty