adl_conformance_no_using.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Boost.Range library
  2. //
  3. // Copyright Thorsten Ottosen 2003-2004. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see http://www.boost.org/libs/range/
  9. //
  10. #include <iostream>
  11. namespace A
  12. {
  13. namespace detail
  14. {
  15. template< typename T >
  16. int f( const T& x )
  17. {
  18. // Default:
  19. std::cout << 1 << std::endl;
  20. return 1;
  21. }
  22. template< typename T >
  23. int adl_f2( const T& x, int* )
  24. {
  25. return f( x );
  26. }
  27. template< typename T >
  28. int adl_f( const T& x )
  29. {
  30. return adl_f2( x, 0 );
  31. }
  32. }
  33. template< typename T >
  34. int f( const T& x )
  35. {
  36. return detail::adl_f( x );
  37. }
  38. template< typename T >
  39. int adl_f2( const T& x, int )
  40. {
  41. return detail::f( x );
  42. }
  43. //--------------------------------
  44. class C {};
  45. /*
  46. // Optional:
  47. int f( const C& x )
  48. {
  49. std::cout << 2 << std::endl;
  50. }
  51. */
  52. template< typename T >
  53. class D {};
  54. /*
  55. // Optional:
  56. template< typename T >
  57. int f( const D< T >& x )
  58. {
  59. std::cout << 3 << std::endl;
  60. }
  61. */
  62. }
  63. namespace B
  64. {
  65. class C {};
  66. // Optional:
  67. /* int f( const C& )
  68. {
  69. std::cout << 4 << std::endl;
  70. }
  71. */
  72. template< typename T >
  73. class D {};
  74. /*
  75. // Optional:
  76. template< typename T >
  77. int f( const D< T >& x )
  78. {
  79. std::cout << 5 << std::endl;
  80. }
  81. */
  82. }
  83. int main()
  84. {
  85. A::f( 42 );
  86. A::C ac;
  87. A::f( ac );
  88. A::D< int > ad;
  89. A::f( ad );
  90. B::C bc;
  91. A::f( bc );
  92. B::D< int > bd;
  93. A::f( bd );
  94. }