Imported Upstream version 1.51.0
[platform/upstream/boost.git] / boost / spirit / home / phoenix / bind / detail / member_function_ptr.hpp
1 /*=============================================================================
2     Copyright (c) 2001-2007 Joel de Guzman
3
4     Distributed under the Boost Software License, Version 1.0. (See accompanying 
5     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #if !defined(BOOST_PP_IS_ITERATING)
8 #if !defined(PHOENIX_BIND_DETAIL_MEMBER_FUNCTION_PTR_HPP)
9 #define PHOENIX_BIND_DETAIL_MEMBER_FUNCTION_PTR_HPP
10
11 #include <boost/preprocessor/iterate.hpp>
12 #include <boost/preprocessor/repetition/enum_params.hpp>
13 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
14 #include <boost/preprocessor/dec.hpp>
15 #include <boost/utility/addressof.hpp>
16
17 namespace boost { namespace phoenix { namespace detail
18 {
19     template <int N>
20     struct member_function_ptr_impl
21     {
22         template <typename RT, typename FP>
23         struct impl;
24     };
25
26     template <int N, typename RT, typename FP>
27     struct member_function_ptr
28         : member_function_ptr_impl<N>::template impl<RT, FP>
29     {
30         typedef typename member_function_ptr_impl<N>::
31             template impl<RT, FP> base;
32         member_function_ptr(FP fp)
33             : base(fp) {}
34     };
35
36     template <>
37     struct member_function_ptr_impl<0>
38     {
39         template <typename RT, typename FP>
40         struct impl
41         {
42             template <typename Class>
43             struct result
44             {
45                 typedef RT type;
46             };
47
48             impl(FP fp)
49                 : fp(fp) {}
50
51             template <typename Class>
52             RT operator()(Class& obj) const
53             {
54                 return (obj.*fp)();
55             }
56
57             template <typename Class>
58             RT operator()(Class* obj) const
59             {
60                 return (obj->*fp)();
61             }
62
63             FP fp;
64         };
65     };
66
67 #define BOOST_PP_ITERATION_PARAMS_1                                             \
68     (3, (1, PHOENIX_COMPOSITE_LIMIT,                                            \
69     "boost/spirit/home/phoenix/bind/detail/member_function_ptr.hpp"))
70 #include BOOST_PP_ITERATE()
71
72 }}} // namespace boost::phoenix::detail
73
74 #endif
75
76 ///////////////////////////////////////////////////////////////////////////////
77 //
78 //  Preprocessor vertical repetition code
79 //
80 ///////////////////////////////////////////////////////////////////////////////
81 #else // defined(BOOST_PP_IS_ITERATING)
82
83 #define N BOOST_PP_ITERATION()
84
85     template <>
86     struct member_function_ptr_impl<N>
87     {
88         template <typename RT, typename FP>
89         struct impl
90         {
91             template <typename Class, BOOST_PP_ENUM_PARAMS(N, typename T)>
92             struct result
93             {
94                 typedef RT type;
95             };
96
97             impl(FP fp)
98                 : fp(fp) {}
99
100             template <typename Class, BOOST_PP_ENUM_PARAMS(N, typename A)>
101             RT operator()(Class& obj, BOOST_PP_ENUM_BINARY_PARAMS(N, A, & _)) const
102             {
103                 return (obj.*fp)(BOOST_PP_ENUM_PARAMS(N, _));
104             }
105
106             template <typename Class, BOOST_PP_ENUM_PARAMS(N, typename A)>
107             RT operator()(Class* obj, BOOST_PP_ENUM_BINARY_PARAMS(N, A, & _)) const
108             {
109                 return (obj->*fp)(BOOST_PP_ENUM_PARAMS(N, _));
110             }
111
112             FP fp;
113         };
114     };
115
116 #undef N
117 #endif // defined(BOOST_PP_IS_ITERATING)
118
119