Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / fusion / functional / adapter / unfused.hpp
1 /*=============================================================================
2     Copyright (c) 2006-2007 Tobias Schwinger
3   
4     Use modification and distribution are subject to the Boost Software 
5     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6     http://www.boost.org/LICENSE_1_0.txt).
7 ==============================================================================*/
8
9 #if !defined(BOOST_FUSION_FUNCTIONAL_ADAPTER_UNFUSED_HPP_INCLUDED)
10 #if !defined(BOOST_PP_IS_ITERATING)
11
12 #include <boost/preprocessor/cat.hpp>
13 #include <boost/preprocessor/iteration/iterate.hpp>
14 #include <boost/preprocessor/repetition/enum_params.hpp>
15 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
16 #include <boost/preprocessor/facilities/intercept.hpp>
17
18 #include <boost/utility/result_of.hpp>
19
20 #include <boost/config.hpp>
21
22 #include <boost/fusion/container/vector/vector.hpp>
23
24 #include <boost/fusion/functional/adapter/limits.hpp>
25 #include <boost/fusion/functional/adapter/detail/access.hpp>
26
27 #if defined (BOOST_MSVC)
28 #  pragma warning(push)
29 #  pragma warning (disable: 4512) // assignment operator could not be generated.
30 #endif
31
32 namespace boost { namespace fusion
33 {
34     template <class Function, bool AllowNullary = true>
35     class unfused;
36
37     //----- ---- --- -- - -  -   -
38
39     template <class Function> 
40     class unfused<Function,true>
41       : public unfused<Function,false>
42     {
43         typedef typename detail::qf_c<Function>::type function_c;
44         typedef typename detail::qf<Function>::type function;
45         typedef typename detail::call_param<Function>::type func_const_fwd_t;
46       public:
47
48         using unfused<Function,false>::operator();
49
50         BOOST_FUSION_GPU_ENABLED inline explicit unfused(func_const_fwd_t f = function())
51             : unfused<Function,false>(f)
52         { }
53
54         typedef typename boost::result_of<
55             function_c(fusion::vector0<> &) >::type call_const_0_result;
56
57         BOOST_FUSION_GPU_ENABLED inline call_const_0_result operator()() const
58         {
59             fusion::vector0<> arg;
60             return this->fnc_transformed(arg);
61         }
62
63         typedef typename boost::result_of< 
64             function(fusion::vector0<> &) >::type call_0_result;
65
66         BOOST_FUSION_GPU_ENABLED inline call_0_result operator()() 
67         {
68             fusion::vector0<> arg;
69             return this->fnc_transformed(arg);
70         }
71     };
72
73     template <class Function> class unfused<Function,false>
74     {
75       protected:
76         Function fnc_transformed;
77         typedef typename detail::qf_c<Function>::type function_c;
78         typedef typename detail::qf<Function>::type function;
79         typedef typename detail::call_param<Function>::type func_const_fwd_t;
80       public:
81
82         BOOST_FUSION_GPU_ENABLED
83         inline explicit unfused(func_const_fwd_t f = function())
84             : fnc_transformed(f)
85         { }
86
87         template <typename Sig>
88         struct result;
89
90         #define  BOOST_PP_FILENAME_1 \
91             <boost/fusion/functional/adapter/unfused.hpp>
92         #define  BOOST_PP_ITERATION_LIMITS \
93             (1,BOOST_FUSION_UNFUSED_MAX_ARITY)
94         #include BOOST_PP_ITERATE()
95     };
96 }}
97
98 #if defined (BOOST_MSVC)
99 #  pragma warning(pop)
100 #endif
101
102 namespace boost 
103 {
104 #if !defined(BOOST_RESULT_OF_USE_DECLTYPE) || defined(BOOST_NO_CXX11_DECLTYPE)
105     template<class F>
106     struct result_of< boost::fusion::unfused<F> const () >
107     {
108         typedef typename boost::fusion::unfused<F>::call_const_0_result type;
109     };
110     template<class F>
111     struct result_of< boost::fusion::unfused<F>() >
112     {
113         typedef typename boost::fusion::unfused<F>::call_0_result type;
114     };
115 #endif
116     template<class F>
117     struct tr1_result_of< boost::fusion::unfused<F> const () >
118     {
119         typedef typename boost::fusion::unfused<F>::call_const_0_result type;
120     };
121     template<class F>
122     struct tr1_result_of< boost::fusion::unfused<F>() >
123     {
124         typedef typename boost::fusion::unfused<F>::call_0_result type;
125     };
126 }
127
128 #define BOOST_FUSION_FUNCTIONAL_ADAPTER_UNFUSED_HPP_INCLUDED
129 #else // defined(BOOST_PP_IS_ITERATING)
130 ////////////////////////////////////////////////////////////////////////////////
131 //
132 //  Preprocessor vertical repetition code
133 //
134 ////////////////////////////////////////////////////////////////////////////////
135 #define N BOOST_PP_ITERATION()
136
137         template <class Self, BOOST_PP_ENUM_PARAMS(N,typename T)>
138         struct result< Self const (BOOST_PP_ENUM_PARAMS(N,T)) >
139             : boost::result_of< function_c(
140                 BOOST_PP_CAT(fusion::vector,N)< BOOST_PP_ENUM_BINARY_PARAMS(N,
141                     typename detail::mref<T,>::type BOOST_PP_INTERCEPT) > & )>
142         { };
143
144         template <class Self, BOOST_PP_ENUM_PARAMS(N,typename T)>
145         struct result< Self(BOOST_PP_ENUM_PARAMS(N,T)) >
146             : boost::result_of< function(
147                 BOOST_PP_CAT(fusion::vector,N)< BOOST_PP_ENUM_BINARY_PARAMS(N,
148                     typename detail::mref<T,>::type BOOST_PP_INTERCEPT) > & )>
149         { };
150
151         template <BOOST_PP_ENUM_PARAMS(N,typename T)>
152         BOOST_FUSION_GPU_ENABLED
153         inline typename boost::result_of<function_c(BOOST_PP_CAT(fusion::vector,N)
154             <BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT)> & )>::type
155         operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& a)) const
156         {
157             BOOST_PP_CAT(fusion::vector,N)<
158                   BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT) >
159                 arg(BOOST_PP_ENUM_PARAMS(N,a));
160             return this->fnc_transformed(arg);
161         }
162
163         template <BOOST_PP_ENUM_PARAMS(N,typename T)>
164         BOOST_FUSION_GPU_ENABLED
165         inline typename boost::result_of<function(BOOST_PP_CAT(fusion::vector,N)
166             <BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT)> & )>::type
167         operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,T,& a)) 
168         {
169             BOOST_PP_CAT(fusion::vector,N)<
170                   BOOST_PP_ENUM_BINARY_PARAMS(N,T,& BOOST_PP_INTERCEPT) >
171                 arg(BOOST_PP_ENUM_PARAMS(N,a));
172             return this->fnc_transformed(arg);
173         }
174 #undef N
175 #endif // defined(BOOST_PP_IS_ITERATING)
176 #endif
177