1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_LAMBDA_PLACEHOLDERS_HPP
12 #define BOOST_COMPUTE_LAMBDA_PLACEHOLDERS_HPP
14 #include <boost/mpl/has_xxx.hpp>
16 #include <boost/compute/lambda/context.hpp>
17 #include <boost/compute/lambda/result_of.hpp>
23 namespace mpl = boost::mpl;
24 namespace proto = boost::proto;
26 // lambda placeholders
27 expression<proto::terminal<placeholder<0> >::type> const _1;
28 expression<proto::terminal<placeholder<1> >::type> const _2;
29 expression<proto::terminal<placeholder<2> >::type> const _3;
33 BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
35 template<class T, bool HasResultType>
36 struct terminal_type_impl;
39 struct terminal_type_impl<T, true>
41 typedef typename T::result_type type;
45 struct terminal_type_impl<T, false>
53 typedef typename terminal_type_impl<T, has_result_type<T>::value>::type type;
56 } // end detail namespace
58 // result_of placeholders
60 struct result_of<expression<proto::terminal<placeholder<0> >::type>, Args, proto::tag::terminal>
62 typedef typename boost::tuples::element<0, Args>::type arg_type;
64 typedef typename detail::terminal_type<arg_type>::type type;
68 struct result_of<expression<proto::terminal<placeholder<1> >::type>, Args, proto::tag::terminal>
70 typedef typename boost::tuples::element<1, Args>::type arg_type;
72 typedef typename detail::terminal_type<arg_type>::type type;
76 struct result_of<expression<proto::terminal<placeholder<2> >::type>, Args, proto::tag::terminal>
78 typedef typename boost::tuples::element<2, Args>::type arg_type;
80 typedef typename detail::terminal_type<arg_type>::type type;
83 } // end lambda namespace
85 // lift lambda placeholders up to the boost::compute namespace
90 } // end compute namespace
91 } // end boost namespace
93 #endif // BOOST_COMPUTE_LAMBDA_PLACEHOLDERS_HPP