eif_partial_specializations.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/utility/enable_if.hpp>
  10. #include <boost/type_traits/is_arithmetic.hpp>
  11. #include <boost/detail/lightweight_test.hpp>
  12. using boost::enable_if_has_type;
  13. using boost::enable_if_c;
  14. using boost::disable_if_c;
  15. using boost::enable_if;
  16. using boost::disable_if;
  17. using boost::is_arithmetic;
  18. template <class T, class Enable = void>
  19. struct tester;
  20. template <class T>
  21. struct tester<T, typename enable_if_c<is_arithmetic<T>::value>::type> {
  22. BOOST_STATIC_CONSTANT(bool, value = true);
  23. };
  24. template <class T>
  25. struct tester<T, typename disable_if_c<is_arithmetic<T>::value>::type> {
  26. BOOST_STATIC_CONSTANT(bool, value = false);
  27. };
  28. template <class T, class Enable = void>
  29. struct tester2;
  30. template <class T>
  31. struct tester2<T, typename enable_if<is_arithmetic<T> >::type> {
  32. BOOST_STATIC_CONSTANT(bool, value = true);
  33. };
  34. template <class T>
  35. struct tester2<T, typename disable_if<is_arithmetic<T> >::type> {
  36. BOOST_STATIC_CONSTANT(bool, value = false);
  37. };
  38. template <class T, class Enable = void>
  39. struct tester3
  40. {
  41. typedef T type;
  42. BOOST_STATIC_CONSTANT(bool, value = false);
  43. };
  44. template <class T>
  45. struct tester3<T, typename enable_if_has_type<typename T::value_type>::type>
  46. {
  47. typedef typename T::value_type type;
  48. BOOST_STATIC_CONSTANT(bool, value = true);
  49. };
  50. struct sample_value_type
  51. {
  52. typedef float***& value_type;
  53. };
  54. int main()
  55. {
  56. BOOST_TEST(tester<int>::value);
  57. BOOST_TEST(tester<double>::value);
  58. BOOST_TEST(!tester<char*>::value);
  59. BOOST_TEST(!tester<void*>::value);
  60. BOOST_TEST(tester2<int>::value);
  61. BOOST_TEST(tester2<double>::value);
  62. BOOST_TEST(!tester2<char*>::value);
  63. BOOST_TEST(!tester2<void*>::value);
  64. BOOST_TEST(!tester3<char*>::value);
  65. BOOST_TEST(tester3<sample_value_type>::value);
  66. return boost::report_errors();
  67. }