4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief type_traits public header */
26 #ifndef HH_SENF_Utils_type_traits_
27 #define HH_SENF_Utils_type_traits_ 1
30 #include <boost/type_traits/function_traits.hpp>
31 #include <boost/type_traits/remove_pointer.hpp>
32 #include <boost/type_traits/is_function.hpp>
33 #include <boost/type_traits/remove_cv.hpp>
34 #include <boost/type_traits/remove_reference.hpp>
35 #include <boost/bind.hpp>
36 #include <senf/config.hh>
38 #include "type_traits.mpp"
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
44 /** \defgroup typetraits Type traits
47 ///\addtogroup typetraits
50 /** \brief Strip first parameter from function traits
52 This meta-function will remove the first argument from \a Traits. The return value is a new
53 function trait with one less argument.
55 If the function described in \a Traits does not take any arguments, it is returned
59 typedef boost::function_traits<void (int, double)> traits
60 BOOST_STATIC_ASSERT(( boost::is_same<
61 senf::function_traits_remove_arg< traits >::type,
62 boost::function_traits<void (double)>
66 \tparam Traits \c boost::function_traits instantiation
68 template < class Traits, unsigned arity = Traits::arity >
69 struct function_traits_remove_arg {};
71 /** \brief Get argument type from function traits
73 function_traits_arg<Traits, index> will return the type of the \a index-th argument from \a
74 Traits. If the function has no argument at that index, \c void is returned
77 typedef boost::function_traits<void (int, double)> traits;
78 BOOST_STATIC_ASSERT(( boost:is_same<
79 senf::function_traits_arg_type< traits, 0 >::type,
82 BOOST_STATIC_ASSERT(( boost::is_same<
83 senf::function_traits_arg_type< traits, 2 >::type,
88 \tparam Traits \c boost::function_traits instantiation
89 \tparam index 0 based argument index
91 template < class Traits, int index, bool flag = (index < Traits::arity) >
92 struct function_traits_arg_type {};
96 template < class Traits, int index >
97 struct function_traits_arg_type <Traits, index, false >
104 /** \brief Remove member pointer from type
106 This meta function will remove any type of member pointer from it's argument. Other types
107 will be returned unchanged.
110 BOOST_STATIC_ASSERT(( boost::is_same<
111 senf::remove_member_pointer< int (Class::*) >::type,
114 BOOST_STATIC_ASSERT(( boost::is_same<
115 senf::remove_member_pointer< void (Class::*)(int) >::type,
120 \tparam MemberPointer type to remove member pointer from
122 template < class MemberPointer > struct remove_member_pointer
124 typedef MemberPointer type;
129 template < class C, class T > struct remove_member_pointer <T (C::*) >
134 template < class C, class T > struct remove_member_pointer <T (C::* const) >
141 /** \brief Get class of a member pointer
143 Returns the class, an arbitrary member pointer belongs to. If the argument is not a member
144 pointer, void is returned.
147 BOOST_STATIC_ASSERT(( boost::is_same<
148 senf::member_class< int (Class::*) >::type,
151 BOOST_STATIC_ASSERT(( boost::is_Same<
152 senf::member_class< int * >::type,
157 \tparam MemberPointer Type to get the member pointer class from
159 template < class MemberPointer > struct member_class
166 template < class C, class T > struct member_class <T (C::*) >
171 template < class C, class T > struct member_class <T (C::* const) >
178 /** \brief Remove any type of pointer from type
180 This meta function will remove a plain or member pointer from the given type. If \a T is
181 neither a member pointer nor an ordinary pointer, \a T will be returned unchanged.
184 BOOST_STATIC_ASSERT(( boost::is_same<
185 senf::remove_any_pointer< int (Class::*) >::type,
188 BOOST_STATIC_ASSERT(( boost::is_same<
189 senf::remove_any_pointer< void (Class::*)(int) >::type,
191 BOOST_STATIC_ASSERT(( boost::is_same<
192 senf::remove_any_pointer < int (*)() >::type,
195 BOOST_STATIC_ASSERT(( boost::is_same<
196 senf::remove_any_pointer < int >::type,
201 \tparam T type to remove member pointer from
204 struct remove_any_pointer
205 : public remove_member_pointer < typename boost::remove_pointer < T >::type >
208 /** \brief Test object if it is a function or member-function (pointer)
210 is_any_function will inherit from \c boost::true_type, when \a T is a function type,
211 function pointer type or a member function pointer type. Otherwise, it will inherit from \c
215 BOOST_STATIC_ASSERT(( senf::is_any_function< void () >::value ));
216 BOOST_STATIC_ASSERT(( senf::is_any_function< void (*)(int) >::value ));
217 BOOST_STATIC_ASSERT(( senf::is_any_function< void (Class::*)() >::value ));
218 BOOST_STATIC_ASSERT(( ! senf::is_any_function< int * >::value ));
221 \tparam T type to test
224 struct is_any_function
225 : public boost::is_function < typename senf::remove_any_pointer < T >::type >
228 /** \brief Remove reference and CV qualification from type
230 remove_cvref will remove all the 'ornaments' from a type as typically used to pass
231 arguments: references and any CV spec. It will thus convert a typical argument type into
235 BOOST_STATIC_ASSERT(( boost::is_same<
236 senf::remove_cvref<int const &>::type,
243 : public boost::remove_cv< typename boost::remove_reference<T>::type >
246 /** \brief Get arity of function T
248 \a T may be any function like type: function, pointer to function or (pointer to)
252 BOOST_STATIC_ASSERT(( senf::function_arity<void (Class::*)(int)>::value == 1 ));
256 struct function_arity
257 : public boost::integral_constant<
259 boost::function_traits<
260 typename senf::remove_any_pointer<T>::type>::arity>
263 /** Test object if it is any \c std::pair type
265 if \a Pair is any \c std::pair type, this trait will inherit from \c boost::true_type,
266 otherwise it will inherit from \c boost::false_type.
269 BOOST_STATIC_ASSERT(( senf::is_pair< std::pair<int,void*> >::value ));
270 BOOST_STATIC_ASSERT(( ! senf::is_pair< void () >::value ));
273 template <class Pair>
275 : public boost::false_type
279 template <class First, class Second>
280 struct is_pair< std::pair<First,Second> >
281 : public boost::true_type
289 # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, 10, \
290 SENF_ABSOLUTE_INCLUDE_PATH(Utils/type_traits.mpp), \
292 # include BOOST_PP_ITERATE()
298 //-/////////////////////////////////////////////////////////////////////////////////////////////////
299 //#include "type_traits.cci"
300 //#include "type_traits.ct"
301 //#include "type_traits.cti"
308 // comment-column: 40
309 // c-file-style: "senf"
310 // indent-tabs-mode: nil
311 // ispell-local-dictionary: "american"
312 // compile-command: "scons -u test"