]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | //---------------------------------------------------------------------------// |
2 | // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com> | |
3 | // | |
4 | // Distributed under the Boost Software License, Version 1.0 | |
5 | // See accompanying file LICENSE_1_0.txt or copy at | |
6 | // http://www.boost.org/LICENSE_1_0.txt | |
7 | // | |
8 | // See http://boostorg.github.com/compute for more information. | |
9 | //---------------------------------------------------------------------------// | |
10 | ||
11 | #ifndef BOOST_COMPUTE_LAMBDA_MAKE_PAIR_HPP | |
12 | #define BOOST_COMPUTE_LAMBDA_MAKE_PAIR_HPP | |
13 | ||
14 | #include <boost/compute/types/pair.hpp> | |
15 | ||
16 | namespace boost { | |
17 | namespace compute { | |
18 | namespace lambda { | |
19 | namespace detail { | |
20 | ||
21 | // function wrapper for make_pair() in lambda expressions | |
22 | struct make_pair_func | |
23 | { | |
24 | template<class Expr, class Args> | |
25 | struct lambda_result | |
26 | { | |
27 | typedef typename proto::result_of::child_c<Expr, 1>::type Arg1; | |
28 | typedef typename proto::result_of::child_c<Expr, 2>::type Arg2; | |
29 | ||
30 | typedef typename lambda::result_of<Arg1, Args>::type T1; | |
31 | typedef typename lambda::result_of<Arg2, Args>::type T2; | |
32 | ||
33 | typedef std::pair<T1, T2> type; | |
34 | }; | |
35 | ||
36 | template<class Context, class Arg1, class Arg2> | |
37 | static void apply(Context &ctx, const Arg1 &arg1, const Arg2 &arg2) | |
38 | { | |
39 | typedef typename lambda::result_of<Arg1, typename Context::args_tuple>::type T1; | |
40 | typedef typename lambda::result_of<Arg2, typename Context::args_tuple>::type T2; | |
41 | ||
42 | ctx.stream << "boost_make_pair("; | |
43 | ctx.stream << type_name<T1>() << ", "; | |
44 | proto::eval(arg1, ctx); | |
45 | ctx.stream << ", "; | |
46 | ctx.stream << type_name<T2>() << ", "; | |
47 | proto::eval(arg2, ctx); | |
48 | ctx.stream << ")"; | |
49 | } | |
50 | }; | |
51 | ||
52 | } // end detail namespace | |
53 | ||
54 | // make_pair(first, second) | |
55 | template<class Arg1, class Arg2> | |
56 | inline typename proto::result_of::make_expr< | |
57 | proto::tag::function, detail::make_pair_func, const Arg1&, const Arg2& | |
58 | >::type const | |
59 | make_pair(const Arg1 &first, const Arg2 &second) | |
60 | { | |
61 | return proto::make_expr<proto::tag::function>( | |
62 | detail::make_pair_func(), ::boost::ref(first), ::boost::ref(second) | |
63 | ); | |
64 | } | |
65 | ||
66 | } // end lambda namespace | |
67 | } // end compute namespace | |
68 | } // end boost namespace | |
69 | ||
70 | #endif // BOOST_COMPUTE_LAMBDA_MAKE_PAIR_HPP |