| 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 | |
| 11 | #include <iostream> |
| 12 | |
| 13 | namespace A |
| 14 | { |
| 15 | namespace detail |
| 16 | { |
| 17 | template< typename T > |
| 18 | int f( const T& x ) |
| 19 | { |
| 20 | // Default: |
| 21 | std::cout << 1 << std::endl; |
| 22 | return 1; |
| 23 | } |
| 24 | |
| 25 | template< typename T > |
| 26 | int adl_f2( const T& x, int* ) |
| 27 | { |
| 28 | return f( x ); |
| 29 | } |
| 30 | |
| 31 | template< typename T > |
| 32 | int adl_f( const T& x ) |
| 33 | { |
| 34 | return adl_f2( x, 0 ); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | template< typename T > |
| 39 | int f( const T& x ) |
| 40 | { |
| 41 | return detail::adl_f( x ); |
| 42 | } |
| 43 | |
| 44 | template< typename T > |
| 45 | int adl_f2( const T& x, int ) |
| 46 | { |
| 47 | return detail::f( x ); |
| 48 | } |
| 49 | |
| 50 | //-------------------------------- |
| 51 | |
| 52 | class C {}; |
| 53 | /* |
| 54 | // Optional: |
| 55 | int f( const C& x ) |
| 56 | { |
| 57 | std::cout << 2 << std::endl; |
| 58 | } |
| 59 | */ |
| 60 | template< typename T > |
| 61 | class D {}; |
| 62 | /* |
| 63 | // Optional: |
| 64 | template< typename T > |
| 65 | int f( const D< T >& x ) |
| 66 | { |
| 67 | std::cout << 3 << std::endl; |
| 68 | } |
| 69 | */ |
| 70 | } |
| 71 | |
| 72 | |
| 73 | namespace B |
| 74 | { |
| 75 | class C {}; |
| 76 | |
| 77 | // Optional: |
| 78 | /* int f( const C& ) |
| 79 | { |
| 80 | std::cout << 4 << std::endl; |
| 81 | } |
| 82 | */ |
| 83 | template< typename T > |
| 84 | class D {}; |
| 85 | /* |
| 86 | // Optional: |
| 87 | template< typename T > |
| 88 | int f( const D< T >& x ) |
| 89 | { |
| 90 | std::cout << 5 << std::endl; |
| 91 | } |
| 92 | */ |
| 93 | } |
| 94 | |
| 95 | int main() |
| 96 | { |
| 97 | A::f( x: 42 ); |
| 98 | |
| 99 | A::C ac; |
| 100 | A::f( x: ac ); |
| 101 | |
| 102 | A::D< int > ad; |
| 103 | A::f( x: ad ); |
| 104 | |
| 105 | B::C bc; |
| 106 | A::f( x: bc ); |
| 107 | |
| 108 | B::D< int > bd; |
| 109 | A::f( x: bd ); |
| 110 | } |
| 111 | |