Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:03

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_HPP
0012 #define BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_HPP
0013 
0014 #include <boost/preprocessor/repetition.hpp>
0015 
0016 #include <boost/compute/config.hpp>
0017 #include <boost/compute/types/tuple.hpp>
0018 
0019 namespace boost {
0020 namespace compute {
0021 namespace lambda {
0022 namespace detail {
0023 
0024 // function wrapper for make_tuple() in lambda expressions
0025 struct make_tuple_func
0026 {
0027     template<class Expr, class Args, int N>
0028     struct make_tuple_result_type;
0029 
0030     #define BOOST_COMPUTE_MAKE_TUPLE_RESULT_GET_ARG(z, n, unused) \
0031         typedef typename proto::result_of::child_c<Expr, BOOST_PP_INC(n)>::type BOOST_PP_CAT(Arg, n);
0032 
0033     #define BOOST_COMPUTE_MAKE_TUPLE_RESULT_GET_ARG_TYPE(z, n, unused) \
0034         typedef typename lambda::result_of<BOOST_PP_CAT(Arg, n), Args>::type BOOST_PP_CAT(T, n);
0035 
0036     #define BOOST_COMPUTE_MAKE_TUPLE_RESULT_TYPE(z, n, unused) \
0037         template<class Expr, class Args> \
0038         struct make_tuple_result_type<Expr, Args, n> \
0039         { \
0040             BOOST_PP_REPEAT(n, BOOST_COMPUTE_MAKE_TUPLE_RESULT_GET_ARG, ~) \
0041             BOOST_PP_REPEAT(n, BOOST_COMPUTE_MAKE_TUPLE_RESULT_GET_ARG_TYPE, ~) \
0042             typedef boost::tuple<BOOST_PP_ENUM_PARAMS(n, T)> type; \
0043         };
0044 
0045     BOOST_PP_REPEAT_FROM_TO(1, BOOST_COMPUTE_MAX_ARITY, BOOST_COMPUTE_MAKE_TUPLE_RESULT_TYPE, ~)
0046 
0047     #undef BOOST_COMPUTE_MAKE_TUPLE_RESULT_GET_ARG
0048     #undef BOOST_COMPUTE_MAKE_TUPLE_RESULT_GET_ARG_TYPE
0049     #undef BOOST_COMPUTE_MAKE_TUPLE_RESULT_TYPE
0050 
0051     template<class Expr, class Args>
0052     struct lambda_result
0053     {
0054         typedef typename make_tuple_result_type<
0055             Expr, Args, proto::arity_of<Expr>::value - 1
0056         >::type type;
0057     };
0058 
0059     #define BOOST_COMPUTE_MAKE_TUPLE_GET_ARG_TYPE(z, n, unused) \
0060         typedef typename lambda::result_of< \
0061             BOOST_PP_CAT(Arg, n), typename Context::args_tuple \
0062         >::type BOOST_PP_CAT(T, n);
0063 
0064     #define BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_APPLY_ARG(z, n, unused) \
0065         BOOST_PP_COMMA_IF(n) BOOST_PP_CAT(const Arg, n) BOOST_PP_CAT(&arg, n)
0066 
0067     #define BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_APPLY_EVAL_ARG(z, n, unused) \
0068         BOOST_PP_EXPR_IF(n, ctx.stream << ", ";) proto::eval(BOOST_PP_CAT(arg, n), ctx);
0069 
0070     #define BOOST_COMPUTE_MAKE_TUPLE_APPLY(z, n, unused) \
0071     template<class Context, BOOST_PP_ENUM_PARAMS(n, class Arg)> \
0072     static void apply(Context &ctx, BOOST_PP_REPEAT(n, BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_APPLY_ARG, ~)) \
0073     { \
0074         BOOST_PP_REPEAT(n, BOOST_COMPUTE_MAKE_TUPLE_GET_ARG_TYPE, ~) \
0075         typedef typename boost::tuple<BOOST_PP_ENUM_PARAMS(n, T)> tuple_type; \
0076         ctx.stream.template inject_type<tuple_type>(); \
0077         ctx.stream << "((" << type_name<tuple_type>() << "){"; \
0078         BOOST_PP_REPEAT(n, BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_APPLY_EVAL_ARG, ~) \
0079         ctx.stream << "})"; \
0080     }
0081 
0082     BOOST_PP_REPEAT_FROM_TO(1, BOOST_COMPUTE_MAX_ARITY, BOOST_COMPUTE_MAKE_TUPLE_APPLY, ~)
0083 
0084     #undef BOOST_COMPUTE_MAKE_TUPLE_GET_ARG_TYPE
0085     #undef BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_APPLY_ARG
0086     #undef BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_APPLY_EVAL_ARG
0087     #undef BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_APPLY
0088 };
0089 
0090 } // end detail namespace
0091 
0092 #define BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_ARG(z, n, unused) \
0093     BOOST_PP_COMMA_IF(n) BOOST_PP_CAT(const Arg, n) BOOST_PP_CAT(&arg, n)
0094 
0095 #define BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_ARG_TYPE(z, n, unused) \
0096     BOOST_PP_COMMA_IF(n) BOOST_PP_CAT(const Arg, n) &
0097 
0098 #define BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_REF_ARG(z, n, unused) \
0099     BOOST_PP_COMMA_IF(n) ::boost::ref(BOOST_PP_CAT(arg, n))
0100 
0101 #define BOOST_COMPUTE_LAMBDA_MAKE_TUPLE(z, n, unused) \
0102 template<BOOST_PP_ENUM_PARAMS(n, class Arg)> \
0103 inline typename proto::result_of::make_expr< \
0104     proto::tag::function, \
0105     detail::make_tuple_func, \
0106     BOOST_PP_REPEAT(n, BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_ARG_TYPE, ~) \
0107 >::type \
0108 make_tuple(BOOST_PP_REPEAT(n, BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_ARG, ~)) \
0109 { \
0110     return proto::make_expr<proto::tag::function>( \
0111         detail::make_tuple_func(), \
0112         BOOST_PP_REPEAT(n, BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_REF_ARG, ~) \
0113     ); \
0114 }
0115 
0116 BOOST_PP_REPEAT_FROM_TO(1, BOOST_COMPUTE_MAX_ARITY, BOOST_COMPUTE_LAMBDA_MAKE_TUPLE, ~)
0117 
0118 #undef BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_ARG
0119 #undef BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_ARG_TYPE
0120 #undef BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_REF_ARG
0121 #undef BOOST_COMPUTE_LAMBDA_MAKE_TUPLE
0122 
0123 } // end lambda namespace
0124 } // end compute namespace
0125 } // end boost namespace
0126 
0127 #endif // BOOST_COMPUTE_LAMBDA_MAKE_TUPLE_HPP