Utils: Add some type traits in type_traits.hh
[senf.git] / Utils / type_traits.mpp
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 Boost.Preprocesser external iteration include */
25
26 #if !BOOST_PP_IS_ITERATING && !defined(MPP_type_traits_)
27 #define MPP_type_traits_ 1
28
29 // Custom includes
30 #include <boost/preprocessor/iteration/iterate.hpp>
31 #include <boost/preprocessor/repetition/enum.hpp>
32 #include <boost/preprocessor/cat.hpp>
33 #include <boost/preprocessor/arithmetic/inc.hpp>
34 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
35 #include <boost/preprocessor/punctuation/comma_if.hpp>
36 #include <boost/preprocessor/arithmetic/dec.hpp>
37 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
38
39 // ///////////////////////////mpp.p////////////////////////////////////////
40 #elif BOOST_PP_IS_ITERATING // ////////////////////////////////////////////
41 // ////////////////////////////////////////////////////////////////////////
42 // Local Macros
43
44 #define mpp_Arg(n) BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(n)), _type)
45
46 #define mpp_OtherArgs_(z,n,d) BOOST_PP_COMMA_IF( BOOST_PP_DEC(n) ) typename traits::mpp_Arg(n)
47 #define mpp_OtherArgs() BOOST_PP_REPEAT_FROM_TO( 1, BOOST_PP_ITERATION(), mpp_OtherArgs_, _ )
48
49 // ////////////////////////////////////////////////////////////////////////
50 #if BOOST_PP_ITERATION_FLAGS()==1 // //////////////////////////////////////
51 // ////////////////////////////////////////////////////////////////////////
52
53 template <class Traits>
54 struct function_traits_remove_arg<Traits, BOOST_PP_ITERATION()>
55 {
56     typedef Traits traits;
57     typedef boost::function_traits<typename traits::result_type( mpp_OtherArgs() )> type;
58 };
59
60 template < class C, class RV
61            BOOST_PP_ENUM_TRAILING_PARAMS( BOOST_PP_ITERATION(), class A ) >
62 struct remove_member_pointer<RV (C::*)(BOOST_PP_ENUM_PARAMS( BOOST_PP_ITERATION(), A ))>
63 {
64     typedef RV type (BOOST_PP_ENUM_PARAMS( BOOST_PP_ITERATION(), A ));
65 };
66
67 template < class C, class RV
68            BOOST_PP_ENUM_TRAILING_PARAMS( BOOST_PP_ITERATION(), class A ) >
69 struct member_class<RV (C::*)(BOOST_PP_ENUM_PARAMS( BOOST_PP_ITERATION(), A ))>
70 {
71     typedef C type;
72 };
73
74 // ////////////////////////////////////////////////////////////////////////
75 #endif // /////////////////////////////////////////////////////////////////
76 // ////////////////////////////////////////////////////////////////////////
77 // Undefine local Macros
78
79 #undef mpp_Args
80 #undef mpp_Args_
81
82 #undef mpp_Arg
83
84 // ////////////////////////////////////////////////////////////////////////
85 #endif // /////////////////////////////////////////////////////////////////
86 // ///////////////////////////mpp.e////////////////////////////////////////
87
88 \f
89 // Local Variables:
90 // mode: c++
91 // fill-column: 100
92 // comment-column: 40
93 // c-file-style: "senf"
94 // indent-tabs-mode: nil
95 // ispell-local-dictionary: "american"
96 // compile-command: "scons -u test"
97 // End: