boost_no_using_breaks_adl.ipp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. // See http://www.boost.org/libs/config for most recent version.
  6. // MACRO: BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL
  7. // TITLE: broken ADL
  8. // DESCRIPTION: Using declarations break argument dependent lookup
  9. // (probably Borland specific), the fix is to use
  10. // using namespace whatever; rather than
  11. // using whatever::symbol;.
  12. namespace boost_ns
  13. {
  14. template <class T>
  15. T* get_pointer(T* p)
  16. { return p; }
  17. namespace inner2
  18. {
  19. template <class T>
  20. struct X {};
  21. template <class T>
  22. T* get_pointer(X<T>)
  23. { return 0; }
  24. }
  25. }
  26. namespace user_ns
  27. {
  28. template <class T>
  29. struct Y{};
  30. template <class T>
  31. T* get_pointer(user_ns::Y<T>)
  32. { return 0; }
  33. template <class T>
  34. int f(T x)
  35. {
  36. // use this as a workaround:
  37. //using namespace boost;
  38. // this statement breaks ADL:
  39. using boost_ns::get_pointer; // conforming compilers require
  40. // this one to find the auto_ptr
  41. // and T* overloads
  42. return get_pointer(x) == 0;
  43. }
  44. }
  45. namespace boost_function_scope_using_declaration_breaks_adl{
  46. int test()
  47. {
  48. int i;
  49. typedef void* pv;
  50. i = user_ns::f(pv());
  51. i = user_ns::f(boost_ns::inner2::X<int>());
  52. (void)i;
  53. return 0;
  54. }
  55. }