switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / type_traits.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief type_traits unit tests */
30
31 //#include "type_traits.test.hh"
32 //#include "type_traits.test.ih"
33
34 // Custom includes
35 #include <boost/static_assert.hpp>
36 #include <boost/type_traits/is_same.hpp>
37 #include "type_traits.hh"
38
39 #include <senf/Utils/auto_unit_test.hh>
40 #include <boost/test/test_tools.hpp>
41
42 #define prefix_
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
44
45 namespace {
46     struct Class;
47 }
48
49 SENF_AUTO_UNIT_TEST(typeTraits)
50 {
51     typedef boost::function_traits<void (int, double)> traits;
52
53     BOOST_STATIC_ASSERT(( boost::is_same<
54         senf::function_traits_remove_arg< traits >::type,
55         boost::function_traits<void (double)>
56     >::value ));
57
58     BOOST_STATIC_ASSERT(( boost::is_same<
59         senf::function_traits_arg_type< traits, 0 >::type,
60         int
61     >::value ));
62     BOOST_STATIC_ASSERT(( boost::is_same<
63         senf::function_traits_arg_type< traits, 2 >::type,
64         void
65     >::value ));
66
67     BOOST_STATIC_ASSERT(( boost::is_same<
68         senf::remove_member_pointer< Class (Class::*) >::type,
69         Class
70     >::value ));
71     BOOST_STATIC_ASSERT(( boost::is_same<
72         senf::remove_member_pointer< Class const (Class::*) >::type,
73         Class const
74     >::value ));
75     BOOST_STATIC_ASSERT(( boost::is_same<
76         senf::remove_member_pointer< Class (Class::*)(int) >::type,
77         Class (int)
78     >::value ));
79     BOOST_STATIC_ASSERT(( boost::is_same<
80         senf::remove_member_pointer< Class const (Class::*)(int) >::type,
81         Class const (int)
82     >::value ));
83     BOOST_STATIC_ASSERT(( boost::is_same<
84         senf::remove_member_pointer< void (Class::*)(int) const>::type,
85         void (int)
86     >::value ));
87     BOOST_STATIC_ASSERT(( boost::is_same<
88         senf::remove_member_pointer< Class const (Class::*)(int) const>::type,
89         Class const (int)
90     >::value ));
91     BOOST_STATIC_ASSERT(( boost::is_same<
92         senf::remove_member_pointer< void (Class::* const)(int)>::type,
93         void (int)
94     >::value ));
95     BOOST_STATIC_ASSERT(( boost::is_same<
96         senf::remove_member_pointer< void (Class::* const)(int) const>::type,
97         void (int)
98     >::value ));
99
100     BOOST_STATIC_ASSERT(( boost::is_same<
101         senf::member_class< int (Class::*) >::type,
102         Class
103     >::value ));
104     BOOST_STATIC_ASSERT(( boost::is_same<
105         senf::member_class< int * >::type,
106         void
107     >::value ));
108
109     BOOST_STATIC_ASSERT(( boost::is_same<
110         senf::remove_any_pointer< int (Class::*) >::type,
111         int
112     >::value ));
113     BOOST_STATIC_ASSERT(( boost::is_same<
114         senf::remove_any_pointer< void (Class::*)(int) >::type,
115         void (int)
116     >::value ));
117     BOOST_STATIC_ASSERT(( boost::is_same<
118         senf::remove_any_pointer < int (*)() >::type,
119         int ()
120     >::value ));
121     BOOST_STATIC_ASSERT(( boost::is_same<
122         senf::remove_any_pointer < int >::type,
123         int
124     >::value ));
125
126     BOOST_STATIC_ASSERT((   senf::is_any_function< void () >::value ));
127     BOOST_STATIC_ASSERT((   senf::is_any_function< void (*)(int) >::value ));
128     BOOST_STATIC_ASSERT((   senf::is_any_function< void (Class::*)() >::value ));
129     BOOST_STATIC_ASSERT((   senf::is_any_function< void (Class::*)() const >::value ));
130     BOOST_STATIC_ASSERT(( ! senf::is_any_function< int * >::value ));
131
132     BOOST_STATIC_ASSERT(( boost::is_same<
133         senf::remove_cvref<int const &>::type,
134         int
135     >::value ));
136
137     BOOST_STATIC_ASSERT(( senf::function_arity<void ()>::value == 0 ));
138     BOOST_STATIC_ASSERT(( senf::function_arity<void (int,int)>::value == 2 ));
139     BOOST_STATIC_ASSERT(( senf::function_arity<void (*)()>::value == 0 ));
140     BOOST_STATIC_ASSERT(( senf::function_arity<void (*)(int,int)>::value == 2 ));
141     BOOST_STATIC_ASSERT(( senf::function_arity<void (Class::*)()>::value == 0 ));
142     BOOST_STATIC_ASSERT(( senf::function_arity<void (Class::*)(int,int)>::value == 2 ));
143
144     BOOST_STATIC_ASSERT(( senf::function_arity<void (Class::*)(int)>::value == 1 ));
145
146     BOOST_STATIC_ASSERT((   senf::is_pair< std::pair<int,void*> >::value ));
147     BOOST_STATIC_ASSERT(( ! senf::is_pair< void () >::value ));
148
149     BOOST_CHECK( true );
150 }
151
152 //-/////////////////////////////////////////////////////////////////////////////////////////////////
153 #undef prefix_
154
155 \f
156 // Local Variables:
157 // mode: c++
158 // fill-column: 100
159 // comment-column: 40
160 // c-file-style: "senf"
161 // indent-tabs-mode: nil
162 // ispell-local-dictionary: "american"
163 // compile-command: "scons -u test"
164 // End: