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_RESULT_OF_HPP
12 #define BOOST_COMPUTE_LAMBDA_RESULT_OF_HPP
14 #include <boost/mpl/vector.hpp>
15 #include <boost/proto/proto.hpp>
17 #include <boost/compute/type_traits/common_type.hpp>
23 namespace mpl = boost::mpl;
24 namespace proto = boost::proto;
26 // meta-function returning the result type of a lambda expression
29 class Tags = typename proto::tag_of<Expr>::type>
35 template<class Expr, class Args>
36 struct result_of<Expr, Args, proto::tag::terminal>
38 typedef typename proto::result_of::value<Expr>::type type;
42 #define BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(tag) \
43 template<class Expr, class Args> \
44 struct result_of<Expr, Args, tag> \
46 typedef typename proto::result_of::child_c<Expr, 0>::type left; \
47 typedef typename proto::result_of::child_c<Expr, 1>::type right; \
49 typedef typename boost::common_type< \
50 typename ::boost::compute::lambda::result_of< \
53 typename proto::tag_of<left>::type>::type, \
54 typename ::boost::compute::lambda::result_of< \
57 typename proto::tag_of<right>::type>::type \
61 BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(proto::tag::plus)
62 BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(proto::tag::minus)
63 BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(proto::tag::multiplies)
64 BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(proto::tag::divides)
65 BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(proto::tag::modulus)
66 BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(proto::tag::bitwise_and)
67 BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(proto::tag::bitwise_or)
68 BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(proto::tag::bitwise_xor)
70 // comparision operators
71 #define BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(tag) \
72 template<class Expr, class Args> \
73 struct result_of<Expr, Args, tag> \
78 BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(proto::tag::less)
79 BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(proto::tag::greater)
80 BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(proto::tag::less_equal)
81 BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(proto::tag::greater_equal)
82 BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(proto::tag::equal_to)
83 BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(proto::tag::not_equal_to)
84 BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(proto::tag::logical_and)
85 BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(proto::tag::logical_or)
87 // assignment operator
88 template<class Expr, class Args>
89 struct result_of<Expr, Args, proto::tag::assign>
91 typedef typename proto::result_of::child_c<Expr, 0>::type left;
92 typedef typename proto::result_of::child_c<Expr, 1>::type right;
94 typedef typename ::boost::compute::lambda::result_of<
95 right, Args, typename proto::tag_of<right>::type
100 template<class Expr, class Args>
101 struct result_of<Expr, Args, proto::tag::function>
103 typedef typename proto::result_of::child_c<Expr, 0>::type func_expr;
104 typedef typename proto::result_of::value<func_expr>::type func;
106 typedef typename func::template lambda_result<Expr, Args>::type type;
109 } // end lambda namespace
110 } // end compute namespace
111 } // end boost namespace
113 #endif // BOOST_COMPUTE_LAMBDA_RESULT_OF_HPP