1ad1a6dac2c03a8ac2994b433209be5592a27e59
[senf.git] / senf / Utils / type_traits.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief type_traits unit tests */
25
26 //#include "type_traits.test.hh"
27 //#include "type_traits.test.ih"
28
29 // Custom includes
30 #include <boost/static_assert.hpp>
31 #include <boost/type_traits/is_same.hpp>
32 #include "type_traits.hh"
33
34 #include <senf/Utils/auto_unit_test.hh>
35 #include <boost/test/test_tools.hpp>
36
37 #define prefix_
38 ///////////////////////////////cc.p////////////////////////////////////////
39
40 namespace {
41     struct Class;
42 }
43
44 SENF_AUTO_UNIT_TEST(typeTraits)
45 {
46     typedef boost::function_traits<void (int, double)> traits;
47
48     BOOST_STATIC_ASSERT(( boost::is_same<
49         senf::function_traits_remove_arg< traits >::type,
50         boost::function_traits<void (double)>
51     >::value ));
52
53     BOOST_STATIC_ASSERT(( boost::is_same<
54         senf::function_traits_arg_type< traits, 0 >::type,
55         int
56     >::value ));
57     BOOST_STATIC_ASSERT(( boost::is_same<
58         senf::function_traits_arg_type< traits, 2 >::type,
59         void
60     >::value ));
61
62     BOOST_STATIC_ASSERT(( boost::is_same<
63         senf::remove_member_pointer< Class (Class::*) >::type,
64         Class
65     >::value ));
66     BOOST_STATIC_ASSERT(( boost::is_same<
67         senf::remove_member_pointer< Class const (Class::*) >::type,
68         Class const
69     >::value ));
70     BOOST_STATIC_ASSERT(( boost::is_same<
71         senf::remove_member_pointer< Class (Class::*)(int) >::type,
72         Class (int)
73     >::value ));
74     BOOST_STATIC_ASSERT(( boost::is_same<
75         senf::remove_member_pointer< Class const (Class::*)(int) >::type,
76         Class const (int)
77     >::value ));
78     BOOST_STATIC_ASSERT(( boost::is_same<
79         senf::remove_member_pointer< void (Class::*)(int) const>::type,
80         void (int)
81     >::value ));
82     BOOST_STATIC_ASSERT(( boost::is_same<
83         senf::remove_member_pointer< Class const (Class::*)(int) const>::type,
84         Class const (int)
85     >::value ));
86     BOOST_STATIC_ASSERT(( boost::is_same<
87         senf::remove_member_pointer< void (Class::* const)(int)>::type,
88         void (int)
89     >::value ));
90     BOOST_STATIC_ASSERT(( boost::is_same<
91         senf::remove_member_pointer< void (Class::* const)(int) const>::type,
92         void (int)
93     >::value ));
94
95     BOOST_STATIC_ASSERT(( boost::is_same<
96         senf::member_class< int (Class::*) >::type,
97         Class
98     >::value ));
99     BOOST_STATIC_ASSERT(( boost::is_same<
100         senf::member_class< int * >::type,
101         void
102     >::value ));
103
104     BOOST_STATIC_ASSERT(( boost::is_same<
105         senf::remove_any_pointer< int (Class::*) >::type,
106         int
107     >::value ));
108     BOOST_STATIC_ASSERT(( boost::is_same<
109         senf::remove_any_pointer< void (Class::*)(int) >::type,
110         void (int)
111     >::value ));
112     BOOST_STATIC_ASSERT(( boost::is_same<
113         senf::remove_any_pointer < int (*)() >::type,
114         int ()
115     >::value ));
116     BOOST_STATIC_ASSERT(( boost::is_same<
117         senf::remove_any_pointer < int >::type,
118         int
119     >::value ));
120
121     BOOST_STATIC_ASSERT((   senf::is_any_function< void () >::value ));
122     BOOST_STATIC_ASSERT((   senf::is_any_function< void (*)(int) >::value ));
123     BOOST_STATIC_ASSERT((   senf::is_any_function< void (Class::*)() >::value ));
124     BOOST_STATIC_ASSERT((   senf::is_any_function< void (Class::*)() const >::value ));
125     BOOST_STATIC_ASSERT(( ! senf::is_any_function< int * >::value ));
126
127     BOOST_STATIC_ASSERT(( boost::is_same<
128         senf::remove_cvref<int const &>::type,
129         int
130     >::value ));
131
132     BOOST_STATIC_ASSERT(( senf::function_arity<void ()>::value == 0 ));
133     BOOST_STATIC_ASSERT(( senf::function_arity<void (int,int)>::value == 2 ));
134     BOOST_STATIC_ASSERT(( senf::function_arity<void (*)()>::value == 0 ));
135     BOOST_STATIC_ASSERT(( senf::function_arity<void (*)(int,int)>::value == 2 ));
136     BOOST_STATIC_ASSERT(( senf::function_arity<void (Class::*)()>::value == 0 ));
137     BOOST_STATIC_ASSERT(( senf::function_arity<void (Class::*)(int,int)>::value == 2 ));
138
139     BOOST_STATIC_ASSERT(( senf::function_arity<void (Class::*)(int)>::value == 1 ));
140
141     BOOST_STATIC_ASSERT((   senf::is_pair< std::pair<int,void*> >::value ));
142     BOOST_STATIC_ASSERT(( ! senf::is_pair< void () >::value ));
143
144     BOOST_CHECK( true );
145 }
146
147 ///////////////////////////////cc.e////////////////////////////////////////
148 #undef prefix_
149
150 \f
151 // Local Variables:
152 // mode: c++
153 // fill-column: 100
154 // comment-column: 40
155 // c-file-style: "senf"
156 // indent-tabs-mode: nil
157 // ispell-local-dictionary: "american"
158 // compile-command: "scons -u test"
159 // End: