fork download
  1. #include <iostream>
  2. #include <iterator>
  3. #include <map>
  4. #include <functional>
  5. #include <type_traits>
  6.  
  7. int main()
  8. {
  9. /////////////// scary iterators check /////////////////////////
  10.  
  11. using map_type_one = std::map< int, char, std::less<int> > ;
  12.  
  13. // container with same value_type etc, but different comparator
  14. using map_type_two = std::map< int, char, std::greater<int> > ;
  15.  
  16. bool containers_are_of_same_type = std::is_same<map_type_one,map_type_two>::value ;
  17. std::cout << "containers are of same type? " << std::boolalpha
  18. << containers_are_of_same_type << '\n' ; // false
  19.  
  20. using iter_type_one = map_type_one::iterator ;
  21. using iter_type_two = map_type_two::iterator ;
  22.  
  23. // is iter_type_one the same as iter_type_two ?
  24. bool iterators_are_of_same_type = std::is_same<iter_type_one,iter_type_two>::value ;
  25. std::cout << "iterators are of same type? "
  26. << iterators_are_of_same_type << '\n' ; // true
  27.  
  28. /////////////// OutputIterator EqualityComparable check /////////////////////////
  29.  
  30. using iterator = std::ostream_iterator<char> ;
  31. iterator one(std::cout) ;
  32. iterator two(std::cout) ;
  33. one = two ; // fine: CopyAssignable
  34. // one == two ; // error: not EqualityComparable
  35.  
  36. }
  37.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
containers are of same type? false
iterators are of same type? true