integral_wrapper_test.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright Aleksey Gurtovoy 2001-2006
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/mpl for documentation.
  8. // $Id$
  9. // $Date$
  10. // $Revision$
  11. #include <boost/mpl/next_prior.hpp>
  12. #include <boost/mpl/aux_/test.hpp>
  13. #include <boost/mpl/aux_/config/workaround.hpp>
  14. #include <cassert>
  15. #if !BOOST_WORKAROUND(__BORLANDC__, < 0x600)
  16. # define INTEGRAL_WRAPPER_RUNTIME_TEST(i, T) \
  17. BOOST_TEST(( WRAPPER(T,i)() == i )); \
  18. BOOST_TEST(( WRAPPER(T,i)::value == i )); \
  19. /**/
  20. #else
  21. # define INTEGRAL_WRAPPER_RUNTIME_TEST(i, T) \
  22. BOOST_TEST(( WRAPPER(T,i)::value == i )); \
  23. /**/
  24. #endif
  25. #if defined(BOOST_NO_CXX11_CONSTEXPR)
  26. #define CONSTEXPR_INTEGRAL_TEST(T, i)
  27. #else
  28. #define CONSTEXPR_INTEGRAL_TEST(T, i) { static_assert(T() == i, "Constexpr for integral constant failed"); }
  29. #endif
  30. #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
  31. // agurt 20/nov/06: see http://article.gmane.org/gmane.comp.lib.boost.devel/151065
  32. #define INTEGRAL_WRAPPER_TEST(unused1, i, T) \
  33. { \
  34. typedef WRAPPER(T,i) borland_tested_type; \
  35. { typedef is_same< borland_tested_type::value_type, T > borland_test_type; \
  36. MPL_ASSERT(( borland_test_type )); } \
  37. { MPL_ASSERT(( is_same< borland_tested_type::type, WRAPPER(T,i) > )); } \
  38. { MPL_ASSERT(( is_same< next< borland_tested_type >::type, WRAPPER(T,i+1) > )); } \
  39. { MPL_ASSERT(( is_same< prior< borland_tested_type >::type, WRAPPER(T,i-1) > )); } \
  40. { MPL_ASSERT_RELATION( (borland_tested_type::value), ==, i ); } \
  41. CONSTEXPR_INTEGRAL_TEST(borland_tested_type, i) \
  42. INTEGRAL_WRAPPER_RUNTIME_TEST(i, T) \
  43. } \
  44. /**/
  45. #else
  46. #define INTEGRAL_WRAPPER_TEST(unused1, i, T) \
  47. { MPL_ASSERT(( is_same< WRAPPER(T,i)::value_type, T > )); } \
  48. { MPL_ASSERT(( is_same< WRAPPER(T,i)::type, WRAPPER(T,i) > )); } \
  49. { MPL_ASSERT(( is_same< next< WRAPPER(T,i) >::type, WRAPPER(T,i+1) > )); } \
  50. { MPL_ASSERT(( is_same< prior< WRAPPER(T,i) >::type, WRAPPER(T,i-1) > )); } \
  51. { MPL_ASSERT_RELATION( (WRAPPER(T,i)::value), ==, i ); } \
  52. CONSTEXPR_INTEGRAL_TEST(WRAPPER(T,i), i) \
  53. INTEGRAL_WRAPPER_RUNTIME_TEST(i, T) \
  54. /**/
  55. #endif