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_PAIR_HPP
0012 #define BOOST_COMPUTE_LAMBDA_MAKE_PAIR_HPP
0013 
0014 #include <boost/compute/types/pair.hpp>
0015 
0016 namespace boost {
0017 namespace compute {
0018 namespace lambda {
0019 namespace detail {
0020 
0021 // function wrapper for make_pair() in lambda expressions
0022 struct make_pair_func
0023 {
0024     template<class Expr, class Args>
0025     struct lambda_result
0026     {
0027         typedef typename proto::result_of::child_c<Expr, 1>::type Arg1;
0028         typedef typename proto::result_of::child_c<Expr, 2>::type Arg2;
0029 
0030         typedef typename lambda::result_of<Arg1, Args>::type T1;
0031         typedef typename lambda::result_of<Arg2, Args>::type T2;
0032 
0033         typedef std::pair<T1, T2> type;
0034     };
0035 
0036     template<class Context, class Arg1, class Arg2>
0037     static void apply(Context &ctx, const Arg1 &arg1, const Arg2 &arg2)
0038     {
0039         typedef typename lambda::result_of<Arg1, typename Context::args_tuple>::type T1;
0040         typedef typename lambda::result_of<Arg2, typename Context::args_tuple>::type T2;
0041 
0042         ctx.stream << "boost_make_pair(";
0043         ctx.stream << type_name<T1>() << ", ";
0044         proto::eval(arg1, ctx);
0045         ctx.stream << ", ";
0046         ctx.stream << type_name<T2>() << ", ";
0047         proto::eval(arg2, ctx);
0048         ctx.stream << ")";
0049     }
0050 };
0051 
0052 } // end detail namespace
0053 
0054 // make_pair(first, second)
0055 template<class Arg1, class Arg2>
0056 inline typename proto::result_of::make_expr<
0057     proto::tag::function, detail::make_pair_func, const Arg1&, const Arg2&
0058 >::type const
0059 make_pair(const Arg1 &first, const Arg2 &second)
0060 {
0061     return proto::make_expr<proto::tag::function>(
0062         detail::make_pair_func(), ::boost::ref(first), ::boost::ref(second)
0063     );
0064 }
0065 
0066 } // end lambda namespace
0067 } // end compute namespace
0068 } // end boost namespace
0069 
0070 #endif // BOOST_COMPUTE_LAMBDA_MAKE_PAIR_HPP