has_xxx.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // Copyright Aleksey Gurtovoy 2000-2004
  2. // Copyright Daniel Walker 2007
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // See http://www.boost.org/libs/mpl for documentation.
  9. // $Id$
  10. // $Date$
  11. // $Revision$
  12. #include <boost/mpl/has_xxx.hpp>
  13. #include <boost/mpl/aux_/config/workaround.hpp>
  14. #include <boost/mpl/aux_/test.hpp>
  15. BOOST_MPL_HAS_XXX_TRAIT_DEF(xxx)
  16. BOOST_MPL_HAS_XXX_TEMPLATE_NAMED_DEF(has_xxx_template, xxx, false)
  17. BOOST_MPL_HAS_XXX_TEMPLATE_DEF(yyy)
  18. struct a1 {};
  19. struct a2 { void xxx(); };
  20. struct a3 { int xxx; };
  21. struct a4 { static int xxx(); };
  22. struct a5 { template< typename T > struct xxx {}; };
  23. struct b1 { typedef int xxx; };
  24. struct b2 { struct xxx; };
  25. struct b3 { typedef int& xxx; };
  26. struct b4 { typedef int* xxx; };
  27. struct b5 { typedef int xxx[10]; };
  28. struct b6 { typedef void (*xxx)(); };
  29. struct b7 { typedef void (xxx)(); };
  30. struct c1 { template< typename T > struct xxx {}; };
  31. struct c2 { template< typename T1, typename T2 > struct xxx {}; };
  32. struct c3 { template< typename T1, typename T2, typename T3 > struct xxx {}; };
  33. struct c4 { template< typename T1, typename T2, typename T3, typename T4 > struct xxx {}; };
  34. struct c5 { template< typename T1, typename T2, typename T3, typename T4, typename T5 > struct xxx {}; };
  35. struct c6 { template< typename T > struct yyy {}; };
  36. struct c7 { template< typename T1, typename T2 > struct yyy {}; };
  37. template< typename T > struct outer;
  38. template< typename T > struct inner { typedef typename T::type type; };
  39. // agurt, 15/aug/04: make sure MWCW passes the test in presence of the following
  40. // template
  41. template< typename T > struct xxx;
  42. MPL_TEST_CASE()
  43. {
  44. MPL_ASSERT_NOT(( has_xxx<int> ));
  45. MPL_ASSERT_NOT(( has_xxx_template<int> ));
  46. #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  47. MPL_ASSERT_NOT(( has_xxx<int&> ));
  48. MPL_ASSERT_NOT(( has_xxx_template<int&> ));
  49. MPL_ASSERT_NOT(( has_xxx<int*> ));
  50. MPL_ASSERT_NOT(( has_xxx_template<int*> ));
  51. MPL_ASSERT_NOT(( has_xxx<int[]> ));
  52. MPL_ASSERT_NOT(( has_xxx_template<int[]> ));
  53. MPL_ASSERT_NOT(( has_xxx<int (*)()> ));
  54. MPL_ASSERT_NOT(( has_xxx_template<int (*)()> ));
  55. MPL_ASSERT_NOT(( has_xxx<a2> ));
  56. MPL_ASSERT_NOT(( has_xxx_template<a2> ));
  57. MPL_ASSERT_NOT(( has_xxx<a3> ));
  58. MPL_ASSERT_NOT(( has_xxx_template<a3> ));
  59. MPL_ASSERT_NOT(( has_xxx<a4> ));
  60. MPL_ASSERT_NOT(( has_xxx_template<a4> ));
  61. #if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3202))
  62. MPL_ASSERT_NOT(( has_xxx<a5> ));
  63. MPL_ASSERT(( has_xxx_template<a5> ));
  64. #endif
  65. MPL_ASSERT_NOT(( has_xxx< enum_ > ));
  66. MPL_ASSERT_NOT(( has_xxx_template< enum_ > ));
  67. #endif
  68. MPL_ASSERT_NOT(( has_xxx<a1> ));
  69. MPL_ASSERT_NOT(( has_xxx_template<a1> ));
  70. MPL_ASSERT_NOT(( has_xxx< outer< inner<int> > > ));
  71. MPL_ASSERT_NOT(( has_xxx_template< outer< inner<int> > > ));
  72. MPL_ASSERT_NOT(( has_xxx< incomplete > ));
  73. MPL_ASSERT_NOT(( has_xxx_template< incomplete > ));
  74. MPL_ASSERT_NOT(( has_xxx< abstract > ));
  75. MPL_ASSERT_NOT(( has_xxx_template< abstract > ));
  76. MPL_ASSERT_NOT(( has_xxx< noncopyable > ));
  77. MPL_ASSERT_NOT(( has_xxx_template< noncopyable > ));
  78. #if !BOOST_WORKAROUND(__COMO_VERSION__, BOOST_TESTED_AT(4308))
  79. MPL_ASSERT_NOT(( has_xxx_template<b1> ));
  80. MPL_ASSERT_NOT(( has_xxx_template<b2> ));
  81. MPL_ASSERT_NOT(( has_xxx_template<b3> ));
  82. MPL_ASSERT_NOT(( has_xxx_template<b4> ));
  83. MPL_ASSERT_NOT(( has_xxx_template<b5> ));
  84. MPL_ASSERT_NOT(( has_xxx_template<b6> ));
  85. MPL_ASSERT_NOT(( has_xxx_template<b7> ));
  86. #endif
  87. // Same name, different args.
  88. MPL_ASSERT(( has_xxx_template<c1> ));
  89. MPL_ASSERT(( has_xxx_template<c2> ));
  90. MPL_ASSERT(( has_xxx_template<c3> ));
  91. MPL_ASSERT(( has_xxx_template<c4> ));
  92. MPL_ASSERT(( has_xxx_template<c5> ));
  93. MPL_ASSERT(( has_yyy<c6> ));
  94. MPL_ASSERT(( has_yyy<c7> ));
  95. // Different name, different args.
  96. MPL_ASSERT_NOT(( has_xxx_template<c6> ));
  97. MPL_ASSERT_NOT(( has_xxx_template<c7> ));
  98. MPL_ASSERT_NOT(( has_yyy<c1> ));
  99. MPL_ASSERT_NOT(( has_yyy<c2> ));
  100. MPL_ASSERT_NOT(( has_yyy<c3> ));
  101. MPL_ASSERT_NOT(( has_yyy<c4> ));
  102. MPL_ASSERT_NOT(( has_yyy<c5> ));
  103. MPL_ASSERT(( has_xxx<b1,true_> ));
  104. MPL_ASSERT(( has_xxx<b2,true_> ));
  105. MPL_ASSERT(( has_xxx<b3,true_> ));
  106. MPL_ASSERT(( has_xxx<b4,true_> ));
  107. MPL_ASSERT(( has_xxx<b5,true_> ));
  108. MPL_ASSERT(( has_xxx<b6,true_> ));
  109. MPL_ASSERT(( has_xxx<b7,true_> ));
  110. MPL_ASSERT(( has_xxx_template<c1,true_> ));
  111. #if !defined(HAS_XXX_ASSERT)
  112. # define HAS_XXX_ASSERT(x) MPL_ASSERT(x)
  113. #endif
  114. HAS_XXX_ASSERT(( has_xxx<b1> ));
  115. HAS_XXX_ASSERT(( has_xxx<b2> ));
  116. HAS_XXX_ASSERT(( has_xxx<b3> ));
  117. HAS_XXX_ASSERT(( has_xxx<b4> ));
  118. HAS_XXX_ASSERT(( has_xxx<b5> ));
  119. HAS_XXX_ASSERT(( has_xxx<b6> ));
  120. HAS_XXX_ASSERT(( has_xxx<b7> ));
  121. #if !defined(HAS_XXX_TEMPLATE_ASSERT)
  122. # define HAS_XXX_TEMPLATE_ASSERT(x) MPL_ASSERT(x)
  123. #endif
  124. HAS_XXX_TEMPLATE_ASSERT(( has_xxx_template<c1> ));
  125. }