assert.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright Aleksey Gurtovoy 2000-2004
  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/assert.hpp>
  12. #include <boost/type_traits/is_same.hpp>
  13. #include <boost/type_traits/is_pointer.hpp>
  14. BOOST_MPL_ASSERT(( boost::is_same<int,int> ));
  15. BOOST_MPL_ASSERT(( boost::is_pointer<int*> ));
  16. BOOST_MPL_ASSERT_NOT(( boost::is_same<int,long> ));
  17. BOOST_MPL_ASSERT_NOT(( boost::is_pointer<int> ));
  18. BOOST_MPL_ASSERT_RELATION( 5, >, 1 );
  19. BOOST_MPL_ASSERT_RELATION( 1, <, 5 );
  20. BOOST_MPL_ASSERT_MSG( true, GLOBAL_SCOPE_ERROR, (int,long) );
  21. BOOST_MPL_ASSERT_MSG( true, ANOTHER_GLOBAL_SCOPE_ERROR, () );
  22. namespace my {
  23. BOOST_MPL_ASSERT(( boost::is_same<int,int> ));
  24. BOOST_MPL_ASSERT(( boost::is_pointer<int*> ));
  25. BOOST_MPL_ASSERT_NOT(( boost::is_same<int,long> ));
  26. BOOST_MPL_ASSERT_NOT(( boost::is_pointer<int> ));
  27. BOOST_MPL_ASSERT_RELATION( 5, >, 1 );
  28. BOOST_MPL_ASSERT_RELATION( 1, <, 5 );
  29. BOOST_MPL_ASSERT_MSG( true, GLOBAL_SCOPE_ERROR, (int,long) );
  30. BOOST_MPL_ASSERT_MSG( true, NAMESPACE_SCOPE_ERROR, () );
  31. BOOST_MPL_ASSERT_MSG( true, ANOTHER_NAMESPACE_SCOPE_ERROR, () );
  32. }
  33. template< typename T >
  34. struct her
  35. {
  36. BOOST_MPL_ASSERT(( boost::is_same<void,T> ));
  37. BOOST_MPL_ASSERT(( boost::is_pointer<T*> ));
  38. BOOST_MPL_ASSERT_NOT(( boost::is_same<int,T> ));
  39. BOOST_MPL_ASSERT_NOT(( boost::is_pointer<T> ));
  40. BOOST_MPL_ASSERT_RELATION( sizeof(T*), >, 1 );
  41. BOOST_MPL_ASSERT_RELATION( 1, <, sizeof(T*) );
  42. BOOST_MPL_ASSERT_MSG( true, GLOBAL_SCOPE_ERROR, (int,long) );
  43. BOOST_MPL_ASSERT_MSG( true, CLASS_SCOPE_ERROR, () );
  44. #if !defined(BOOST_MPL_CFG_NO_DEFAULT_PARAMETERS_IN_NESTED_TEMPLATES)
  45. BOOST_MPL_ASSERT_MSG( true, ANOTHER_CLASS_SCOPE_ERROR, (types<int, T>) );
  46. #endif
  47. void f()
  48. {
  49. BOOST_MPL_ASSERT(( boost::is_same<void,T> ));
  50. BOOST_MPL_ASSERT(( boost::is_pointer<T*> ));
  51. BOOST_MPL_ASSERT_NOT(( boost::is_same<int,T> ));
  52. BOOST_MPL_ASSERT_NOT(( boost::is_pointer<T> ));
  53. BOOST_MPL_ASSERT_RELATION( sizeof(T*), >, 1 );
  54. BOOST_MPL_ASSERT_RELATION( 1, <, sizeof(T*) );
  55. #if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3202))
  56. BOOST_MPL_ASSERT_MSG( true, GLOBAL_SCOPE_ERROR, (int,long) );
  57. #endif
  58. BOOST_MPL_ASSERT_MSG( true, MEMBER_FUNCTION_SCOPE_ERROR, () );
  59. #if !defined(BOOST_MPL_CFG_NO_DEFAULT_PARAMETERS_IN_NESTED_TEMPLATES)
  60. BOOST_MPL_ASSERT_MSG( true, ANOTHER_MEMBER_FUNCTION_SCOPE_ERROR, (types<int, T>) );
  61. #endif
  62. }
  63. };
  64. template<class T>
  65. struct nested : boost::mpl::true_ {
  66. BOOST_MPL_ASSERT(( boost::is_pointer<T*> ));
  67. BOOST_MPL_ASSERT_NOT(( boost::is_same<void,T> ));
  68. BOOST_MPL_ASSERT_RELATION( sizeof(T*), >, 1 );
  69. BOOST_MPL_ASSERT_MSG( true, GLOBAL_SCOPE_ERROR, (int,long) );
  70. };
  71. BOOST_MPL_ASSERT(( nested<int> ));
  72. BOOST_MPL_ASSERT_NOT(( boost::mpl::not_<nested<unsigned> > ));
  73. int main()
  74. {
  75. her<void> h;
  76. h.f();
  77. BOOST_MPL_ASSERT(( boost::is_same<int,int> ));
  78. BOOST_MPL_ASSERT(( boost::is_pointer<int*> ));
  79. BOOST_MPL_ASSERT_NOT(( boost::is_same<int,long> ));
  80. BOOST_MPL_ASSERT_NOT(( boost::is_pointer<int> ));
  81. BOOST_MPL_ASSERT_RELATION( 5, >, 1 );
  82. BOOST_MPL_ASSERT_RELATION( 1, <, 5 );
  83. BOOST_MPL_ASSERT_MSG( true, GLOBAL_SCOPE_ERROR, (int,long) );
  84. BOOST_MPL_ASSERT_MSG( true, FUNCTION_SCOPE_ERROR, () );
  85. BOOST_MPL_ASSERT_MSG( true, ANOTHER_FUNCTION_SCOPE_ERROR, () );
  86. return 0;
  87. }