eif_namespace_disambiguation.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Boost enable_if library
  2. // Copyright 2003 (c) The Trustees of Indiana University.
  3. // Use, modification, and distribution is subject to the Boost Software
  4. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // Authors: Jaakko Jarvi (jajarvi at osl.iu.edu)
  7. // Jeremiah Willcock (jewillco at osl.iu.edu)
  8. // Andrew Lumsdaine (lums at osl.iu.edu)
  9. #include <boost/config.hpp>
  10. #include <boost/utility/enable_if.hpp>
  11. #include <boost/type_traits/is_arithmetic.hpp>
  12. #include <boost/detail/lightweight_test.hpp>
  13. using boost::enable_if;
  14. using boost::is_arithmetic;
  15. template<class T> struct not_
  16. {
  17. BOOST_STATIC_CONSTANT( bool, value = !T::value );
  18. };
  19. namespace A {
  20. template<class T>
  21. typename enable_if<is_arithmetic<T>, bool>::type
  22. arithmetic_object(T t) { return true; }
  23. }
  24. namespace B {
  25. template<class T>
  26. typename enable_if<not_<is_arithmetic<T> >, bool>::type
  27. arithmetic_object(T t) { return false; }
  28. }
  29. int main()
  30. {
  31. using namespace A;
  32. using namespace B;
  33. BOOST_TEST(arithmetic_object(1));
  34. BOOST_TEST(arithmetic_object(1.0));
  35. BOOST_TEST(!arithmetic_object("1"));
  36. BOOST_TEST(!arithmetic_object(static_cast<void*>(0)));
  37. return boost::report_errors();
  38. }