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