File indexing completed on 2025-01-18 09:30:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_LAMBDA_RESULT_OF_HPP
0012 #define BOOST_COMPUTE_LAMBDA_RESULT_OF_HPP
0013
0014 #include <boost/mpl/vector.hpp>
0015 #include <boost/proto/proto.hpp>
0016
0017 #include <boost/compute/type_traits/common_type.hpp>
0018
0019 namespace boost {
0020 namespace compute {
0021 namespace lambda {
0022
0023 namespace mpl = boost::mpl;
0024 namespace proto = boost::proto;
0025
0026
0027 template<class Expr,
0028 class Args = void,
0029 class Tags = typename proto::tag_of<Expr>::type>
0030 struct result_of
0031 {
0032 };
0033
0034
0035 template<class Expr, class Args>
0036 struct result_of<Expr, Args, proto::tag::terminal>
0037 {
0038 typedef typename proto::result_of::value<Expr>::type type;
0039 };
0040
0041
0042 #define BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(tag) \
0043 template<class Expr, class Args> \
0044 struct result_of<Expr, Args, tag> \
0045 { \
0046 typedef typename proto::result_of::child_c<Expr, 0>::type left; \
0047 typedef typename proto::result_of::child_c<Expr, 1>::type right; \
0048 \
0049 typedef typename boost::common_type< \
0050 typename ::boost::compute::lambda::result_of< \
0051 left, \
0052 Args, \
0053 typename proto::tag_of<left>::type>::type, \
0054 typename ::boost::compute::lambda::result_of< \
0055 right, \
0056 Args, \
0057 typename proto::tag_of<right>::type>::type \
0058 >::type type; \
0059 };
0060
0061 BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(proto::tag::plus)
0062 BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(proto::tag::minus)
0063 BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(proto::tag::multiplies)
0064 BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(proto::tag::divides)
0065 BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(proto::tag::modulus)
0066 BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(proto::tag::bitwise_and)
0067 BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(proto::tag::bitwise_or)
0068 BOOST_COMPUTE_LAMBDA_RESULT_OF_BINARY_OPERATOR(proto::tag::bitwise_xor)
0069
0070
0071 #define BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(tag) \
0072 template<class Expr, class Args> \
0073 struct result_of<Expr, Args, tag> \
0074 { \
0075 typedef bool type; \
0076 };
0077
0078 BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(proto::tag::less)
0079 BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(proto::tag::greater)
0080 BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(proto::tag::less_equal)
0081 BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(proto::tag::greater_equal)
0082 BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(proto::tag::equal_to)
0083 BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(proto::tag::not_equal_to)
0084 BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(proto::tag::logical_and)
0085 BOOST_COMPUTE_LAMBDA_RESULT_OF_COMPARISON_OPERATOR(proto::tag::logical_or)
0086
0087
0088 template<class Expr, class Args>
0089 struct result_of<Expr, Args, proto::tag::assign>
0090 {
0091 typedef typename proto::result_of::child_c<Expr, 0>::type left;
0092 typedef typename proto::result_of::child_c<Expr, 1>::type right;
0093
0094 typedef typename ::boost::compute::lambda::result_of<
0095 right, Args, typename proto::tag_of<right>::type
0096 >::type type;
0097 };
0098
0099
0100 template<class Expr, class Args>
0101 struct result_of<Expr, Args, proto::tag::function>
0102 {
0103 typedef typename proto::result_of::child_c<Expr, 0>::type func_expr;
0104 typedef typename proto::result_of::value<func_expr>::type func;
0105
0106 typedef typename func::template lambda_result<Expr, Args>::type type;
0107 };
0108
0109 }
0110 }
0111 }
0112
0113 #endif