Blame view

3rdparty/boost_1_81_0/libs/mpl/test/assert.cpp 3.49 KB
73ef4ff3   Hu Chunming   提交三方库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  
  // Copyright Aleksey Gurtovoy 2000-2004
  //
  // Distributed under the Boost Software License, Version 1.0. 
  // (See accompanying file LICENSE_1_0.txt or copy at 
  // http://www.boost.org/LICENSE_1_0.txt)
  //
  // See http://www.boost.org/libs/mpl for documentation.
  
  // $Id$
  // $Date$
  // $Revision$
  
  #include <boost/mpl/assert.hpp>
  
  #include <boost/type_traits/is_same.hpp>
  #include <boost/type_traits/is_pointer.hpp>
  
  
  BOOST_MPL_ASSERT(( boost::is_same<int,int> ));
  BOOST_MPL_ASSERT(( boost::is_pointer<int*> ));
  BOOST_MPL_ASSERT_NOT(( boost::is_same<int,long> ));
  BOOST_MPL_ASSERT_NOT(( boost::is_pointer<int> ));
  BOOST_MPL_ASSERT_RELATION( 5, >, 1 );
  BOOST_MPL_ASSERT_RELATION( 1, <, 5 );
  BOOST_MPL_ASSERT_MSG( true, GLOBAL_SCOPE_ERROR, (int,long) );
  BOOST_MPL_ASSERT_MSG( true, ANOTHER_GLOBAL_SCOPE_ERROR, () );
  
  namespace my {
  BOOST_MPL_ASSERT(( boost::is_same<int,int> ));
  BOOST_MPL_ASSERT(( boost::is_pointer<int*> ));
  BOOST_MPL_ASSERT_NOT(( boost::is_same<int,long> ));
  BOOST_MPL_ASSERT_NOT(( boost::is_pointer<int> ));
  BOOST_MPL_ASSERT_RELATION( 5, >, 1 );
  BOOST_MPL_ASSERT_RELATION( 1, <, 5 );
  BOOST_MPL_ASSERT_MSG( true, GLOBAL_SCOPE_ERROR, (int,long) );
  BOOST_MPL_ASSERT_MSG( true, NAMESPACE_SCOPE_ERROR, () );
  BOOST_MPL_ASSERT_MSG( true, ANOTHER_NAMESPACE_SCOPE_ERROR, () );
  }
  
  template< typename T >
  struct her
  {
      BOOST_MPL_ASSERT(( boost::is_same<void,T> ));
      BOOST_MPL_ASSERT(( boost::is_pointer<T*> ));
      BOOST_MPL_ASSERT_NOT(( boost::is_same<int,T> ));
      BOOST_MPL_ASSERT_NOT(( boost::is_pointer<T> ));
      BOOST_MPL_ASSERT_RELATION( sizeof(T*), >, 1 );
      BOOST_MPL_ASSERT_RELATION( 1, <, sizeof(T*) );
      BOOST_MPL_ASSERT_MSG( true, GLOBAL_SCOPE_ERROR, (int,long) );
      BOOST_MPL_ASSERT_MSG( true, CLASS_SCOPE_ERROR, () );
  #if !defined(BOOST_MPL_CFG_NO_DEFAULT_PARAMETERS_IN_NESTED_TEMPLATES)
      BOOST_MPL_ASSERT_MSG( true, ANOTHER_CLASS_SCOPE_ERROR, (types<int, T>) );
  #endif
  
      void f()
      {
          BOOST_MPL_ASSERT(( boost::is_same<void,T> ));
          BOOST_MPL_ASSERT(( boost::is_pointer<T*> ));
          BOOST_MPL_ASSERT_NOT(( boost::is_same<int,T> ));
          BOOST_MPL_ASSERT_NOT(( boost::is_pointer<T> ));
          BOOST_MPL_ASSERT_RELATION( sizeof(T*), >, 1 );
          BOOST_MPL_ASSERT_RELATION( 1, <, sizeof(T*) );
  #if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3202))
          BOOST_MPL_ASSERT_MSG( true, GLOBAL_SCOPE_ERROR, (int,long) );
  #endif
          BOOST_MPL_ASSERT_MSG( true, MEMBER_FUNCTION_SCOPE_ERROR, () );
  #if !defined(BOOST_MPL_CFG_NO_DEFAULT_PARAMETERS_IN_NESTED_TEMPLATES)
          BOOST_MPL_ASSERT_MSG( true, ANOTHER_MEMBER_FUNCTION_SCOPE_ERROR, (types<int, T>) );
  #endif
      }
  };
  
  template<class T>
  struct nested : boost::mpl::true_ {
      BOOST_MPL_ASSERT(( boost::is_pointer<T*> ));
      BOOST_MPL_ASSERT_NOT(( boost::is_same<void,T> ));
      BOOST_MPL_ASSERT_RELATION( sizeof(T*), >, 1 );
      BOOST_MPL_ASSERT_MSG( true, GLOBAL_SCOPE_ERROR, (int,long) );
  };
  
  BOOST_MPL_ASSERT(( nested<int> ));
  BOOST_MPL_ASSERT_NOT(( boost::mpl::not_<nested<unsigned> > ));
  
  int main()
  {
      her<void> h;
      h.f();
      
      BOOST_MPL_ASSERT(( boost::is_same<int,int> ));
      BOOST_MPL_ASSERT(( boost::is_pointer<int*> ));
      BOOST_MPL_ASSERT_NOT(( boost::is_same<int,long> ));
      BOOST_MPL_ASSERT_NOT(( boost::is_pointer<int> ));
      BOOST_MPL_ASSERT_RELATION( 5, >, 1 );
      BOOST_MPL_ASSERT_RELATION( 1, <, 5 );
      BOOST_MPL_ASSERT_MSG( true, GLOBAL_SCOPE_ERROR, (int,long) );
      BOOST_MPL_ASSERT_MSG( true, FUNCTION_SCOPE_ERROR, () );
      BOOST_MPL_ASSERT_MSG( true, ANOTHER_FUNCTION_SCOPE_ERROR, () );
  
      return 0;
  }