File indexing completed on 2025-01-18 09:34:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #if !defined(BOOST_FUSION_FUNCTIONAL_INVOCATION_INVOKE_FUNCTION_OBJECT_HPP_INCLUDED)
0011 #if !defined(BOOST_PP_IS_ITERATING)
0012
0013 #include <boost/preprocessor/cat.hpp>
0014 #include <boost/preprocessor/iteration/iterate.hpp>
0015 #include <boost/preprocessor/arithmetic/dec.hpp>
0016 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
0017 #include <boost/preprocessor/repetition/enum.hpp>
0018 #include <boost/preprocessor/repetition/enum_params.hpp>
0019
0020 #include <boost/utility/result_of.hpp>
0021 #include <boost/core/enable_if.hpp>
0022
0023 #include <boost/type_traits/remove_reference.hpp>
0024 #include <boost/type_traits/remove_const.hpp>
0025
0026 #include <boost/fusion/support/category_of.hpp>
0027 #include <boost/fusion/sequence/intrinsic/size.hpp>
0028 #include <boost/fusion/sequence/intrinsic/at.hpp>
0029 #include <boost/fusion/sequence/intrinsic/begin.hpp>
0030 #include <boost/fusion/iterator/next.hpp>
0031 #include <boost/fusion/iterator/deref.hpp>
0032 #include <boost/fusion/functional/invocation/limits.hpp>
0033
0034 namespace boost { namespace fusion
0035 {
0036 namespace detail
0037 {
0038 template<
0039 class Function, class Sequence,
0040 int N = result_of::size<Sequence>::value,
0041 bool RandomAccess = traits::is_random_access<Sequence>::value,
0042 typename Enable = void
0043 >
0044 struct invoke_function_object_impl;
0045
0046 template <class Sequence, int N>
0047 struct invoke_function_object_param_types;
0048
0049 #define BOOST_PP_FILENAME_1 \
0050 <boost/fusion/functional/invocation/invoke_function_object.hpp>
0051 #define BOOST_PP_ITERATION_LIMITS \
0052 (0, BOOST_FUSION_INVOKE_FUNCTION_OBJECT_MAX_ARITY)
0053 #include BOOST_PP_ITERATE()
0054 }
0055
0056 namespace result_of
0057 {
0058 template <class Function, class Sequence, class Enable = void>
0059 struct invoke_function_object;
0060
0061 template <class Function, class Sequence>
0062 struct invoke_function_object<Function, Sequence,
0063 typename enable_if_has_type<
0064 typename detail::invoke_function_object_impl<
0065 typename boost::remove_reference<Function>::type, Sequence
0066 >::result_type
0067 >::type>
0068 {
0069 typedef typename detail::invoke_function_object_impl<
0070 typename boost::remove_reference<Function>::type, Sequence
0071 >::result_type type;
0072 };
0073 }
0074
0075 template <class Function, class Sequence>
0076 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0077 inline typename result_of::invoke_function_object<Function,Sequence>::type
0078 invoke_function_object(Function f, Sequence & s)
0079 {
0080 return detail::invoke_function_object_impl<
0081 typename boost::remove_reference<Function>::type,Sequence
0082 >::call(f,s);
0083 }
0084
0085 template <class Function, class Sequence>
0086 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0087 inline typename result_of::invoke_function_object<Function,Sequence const>::type
0088 invoke_function_object(Function f, Sequence const & s)
0089 {
0090 return detail::invoke_function_object_impl<
0091 typename boost::remove_reference<Function>::type,Sequence const
0092 >::call(f,s);
0093 }
0094
0095 }}
0096
0097 #define BOOST_FUSION_FUNCTIONAL_INVOCATION_INVOKE_FUNCTION_OBJECT_HPP_INCLUDED
0098 #else
0099
0100
0101
0102
0103
0104 #define N BOOST_PP_ITERATION()
0105
0106 #define M(z,j,data) \
0107 typename result_of::at_c<Sequence,j>::type
0108
0109 template <class Function, class Sequence>
0110 struct invoke_function_object_impl<Function,Sequence,N,true,
0111 typename enable_if_has_type<
0112 typename boost::result_of<Function (BOOST_PP_ENUM(N,M,~)) >::type
0113 >::type>
0114 {
0115 public:
0116
0117 typedef typename boost::result_of<
0118 Function (BOOST_PP_ENUM(N,M,~)) >::type result_type;
0119 #undef M
0120
0121 #if N > 0
0122
0123 template <class F>
0124 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0125 static inline result_type
0126 call(F & f, Sequence & s)
0127 {
0128 #define M(z,j,data) fusion::at_c<j>(s)
0129 return f( BOOST_PP_ENUM(N,M,~) );
0130 #undef M
0131 }
0132
0133 #else
0134
0135 template <class F>
0136 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0137 static inline result_type
0138 call(F & f, Sequence & )
0139 {
0140 return f();
0141 }
0142
0143 #endif
0144
0145 };
0146
0147 #define M(z,j,data) \
0148 typename invoke_function_object_param_types<Sequence,N>::T ## j
0149
0150 template <class Function, class Sequence>
0151 struct invoke_function_object_impl<Function,Sequence,N,false,
0152 typename enable_if_has_type<
0153 typename boost::result_of<Function (BOOST_PP_ENUM(N,M,~)) >::type
0154 >::type>
0155 #undef M
0156 {
0157 private:
0158 typedef invoke_function_object_param_types<Sequence,N> seq;
0159 public:
0160 typedef typename boost::result_of<
0161 Function (BOOST_PP_ENUM_PARAMS(N,typename seq::T))
0162 >::type result_type;
0163
0164 #if N > 0
0165
0166 template <class F>
0167 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0168 static inline result_type
0169 call(F & f, Sequence & s)
0170 {
0171 typename seq::I0 i0 = fusion::begin(s);
0172 #define M(z,j,data) \
0173 typename seq::I##j i##j = \
0174 fusion::next(BOOST_PP_CAT(i,BOOST_PP_DEC(j)));
0175 BOOST_PP_REPEAT_FROM_TO(1,N,M,~)
0176 #undef M
0177 return f( BOOST_PP_ENUM_PARAMS(N,*i) );
0178 }
0179
0180 #else
0181
0182 template <class F>
0183 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0184 static inline result_type
0185 call(F & f, Sequence & )
0186 {
0187 return f();
0188 }
0189
0190 #endif
0191
0192 };
0193
0194 template <class Sequence>
0195 struct invoke_function_object_param_types<Sequence,N>
0196 {
0197 #if N > 0
0198 typedef typename result_of::begin<Sequence>::type I0;
0199 typedef typename result_of::deref<I0>::type T0;
0200
0201 #define M(z,i,data) \
0202 typedef typename result_of::next< \
0203 BOOST_PP_CAT(I,BOOST_PP_DEC(i))>::type I##i; \
0204 typedef typename result_of::deref<I##i>::type T##i;
0205
0206 BOOST_PP_REPEAT_FROM_TO(1,N,M,~)
0207 #undef M
0208 #endif
0209 };
0210
0211 #undef N
0212 #endif
0213 #endif
0214