• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//  (C) Copyright John Maddock 2001.
2//  Use, modification and distribution are subject to the
3//  Boost Software License, Version 1.0. (See accompanying file
4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6//  See http://www.boost.org/libs/config for most recent version.
7
8//  MACRO:         BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL
9//  TITLE:         broken ADL
10//  DESCRIPTION:   Using declarations break argument dependent lookup
11//                 (probably Borland specific), the fix is to use
12//                 using namespace whatever; rather than
13//                 using whatever::symbol;.
14
15
16namespace boost_ns
17{
18   template <class T>
19   T* get_pointer(T* p)
20   { return p; }
21
22   namespace inner2
23   {
24      template <class T>
25      struct X {};
26
27      template <class T>
28      T* get_pointer(X<T>)
29      { return 0; }
30   }
31}
32
33namespace user_ns
34{
35   template <class T>
36   struct Y{};
37
38   template <class T>
39   T* get_pointer(user_ns::Y<T>)
40   { return 0; }
41
42   template <class T>
43   int f(T x)
44   {
45      // use this as a workaround:
46      //using namespace boost;
47      // this statement breaks ADL:
48      using boost_ns::get_pointer;    // conforming compilers require
49                                   // this one to find the auto_ptr
50                                   // and T* overloads
51      return get_pointer(x) == 0;
52   }
53}
54
55namespace boost_function_scope_using_declaration_breaks_adl{
56
57int test()
58{
59   int i;
60   typedef void* pv;
61   i = user_ns::f(pv());
62   i = user_ns::f(boost_ns::inner2::X<int>());
63   (void)i;
64   return 0;
65}
66
67}
68
69
70
71
72
73
74