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_FUNCTIONAL_OPERATORS_HPP
12 #define BOOST_COMPUTE_FUNCTIONAL_OPERATORS_HPP
20 template<class Expr1, class Expr2, class Result>
21 struct invoked_binary_operator
23 typedef Result result_type;
25 invoked_binary_operator(const std::string &op,
34 std::string op() const
54 } // end detail namespace
57 #define BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(name, op, return_type, arg_type) \
58 template<class arg_type> \
59 class name : public function<return_type (arg_type, arg_type)> \
62 name() : function<return_type (arg_type, arg_type)>(BOOST_PP_STRINGIZE(name)) { } \
64 template<class Arg1, class Arg2> \
65 detail::invoked_binary_operator<Arg1, Arg2, T> \
66 operator()(const Arg1 &x, const Arg2 &y) const \
68 return detail::invoked_binary_operator<Arg1, Arg2, T>(op, x, y); \
72 // arithmetic operations
73 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(plus, "+", T, T)
74 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(minus, "-", T, T)
75 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(multiplies, "*", T, T)
76 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(divides, "/", T, T)
77 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(modulus, "%", T, T)
80 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(equal_to, "==", T, T)
81 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(not_equal_to, "!=", T, T)
82 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(greater, ">", T, T)
83 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(less, "<", T, T)
84 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(greater_equal, ">=", T, T)
85 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(less_equal, "<=", T, T)
88 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(logical_and, "&&", T, T)
89 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(logical_or, "||", T, T)
92 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(bit_and, "&", T, T)
93 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(bit_or, "|", T, T)
94 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(bit_xor, "^", T, T)
95 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(shift_left, "<<", T, T)
96 BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(shift_right, ">>", T, T)
98 } // end compute namespace
99 } // end boost namespace
100 #endif // BOOST_COMPUTE_FUNCTIONAL_OPERATORS_HPP