fork download
  1. #include <iostream>
  2.  
  3. template < typename T > void foo( T, typename T::const_iterator* = nullptr )
  4. { std::cout << "(1) this type defines a nested type 'const_iterator'\n" ; }
  5.  
  6. template < typename T > void foo( T, typename T::first_type* = nullptr )
  7. { std::cout << "(2) this type defines a nested type 'first_type'\n" ; }
  8.  
  9. template < typename T > void foo( T, typename T::result_type* = nullptr )
  10. { std::cout << "(3) this type defines a nested type 'result_type'\n" ; }
  11.  
  12. #include <vector>
  13. #include <utility>
  14. #include <functional>
  15.  
  16. int main()
  17. {
  18. std::vector<int> a ;
  19. foo(a) ; // (1) this type defines a nested type 'const_iterator'
  20. // substitution failure for (2) and (3)
  21.  
  22. std::pair<int,int> b ;
  23. foo(b) ; // (2) this type defines a nested type 'first_type'
  24. // substitution failure for (1) and (3)
  25.  
  26. std::function< bool(int,int) > c ;
  27. foo(c) ; // (3) this type defines a nested type 'result_type'
  28. // substitution failure for (1) and (2)
  29. }
  30.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
(1) this type defines a nested type 'const_iterator'
(2) this type defines a nested type 'first_type'
(3) this type defines a nested type 'result_type'