/////////////////////////////////////////////////////////////////////////////// /// \file operators.hpp /// Contains all the overloaded operators that make it possible to build /// expression templates using proto components // // Copyright 2004 Eric Niebler. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_PROTO_OPERATORS_HPP_EAN_04_01_2005 #define BOOST_PROTO_OPERATORS_HPP_EAN_04_01_2005 #include #include #include #include #include #include namespace boost { namespace proto { /////////////////////////////////////////////////////////////////////////////// // unary_op_generator template struct unary_op_generator { typedef unary_op< typename as_op::type , Tag > type; }; /////////////////////////////////////////////////////////////////////////////// // binary_op_generator template struct binary_op_generator { typedef binary_op< typename as_op::type , typename as_op::type , Tag > type; }; /////////////////////////////////////////////////////////////////////////////// // unary operators template unary_op const noop(Arg const &arg) { return make_op(arg); } #define BOOST_PROTO_UNARY_OP(op, tag) \ template \ inline typename lazy_enable_if, unary_op_generator >::type const \ operator op(Arg const &arg) \ { \ return make_op(as_op::make(arg)); \ } #define BOOST_PROTO_BINARY_OP(op, tag) \ template \ inline typename lazy_enable_if< \ mpl::or_, is_op > \ , binary_op_generator \ >::type const \ operator op(Left const &left, Right const &right) \ { \ return make_op(as_op::make(left), as_op::make(right)); \ } BOOST_PROTO_UNARY_OP(+, unary_plus_tag) BOOST_PROTO_UNARY_OP(-, unary_minus_tag) BOOST_PROTO_UNARY_OP(*, unary_star_tag) BOOST_PROTO_UNARY_OP(~, complement_tag) BOOST_PROTO_UNARY_OP(&, address_of_tag) BOOST_PROTO_UNARY_OP(!, logical_not_tag) BOOST_PROTO_UNARY_OP(++, pre_inc_tag) BOOST_PROTO_UNARY_OP(--, pre_dec_tag) BOOST_PROTO_BINARY_OP(<<, left_shift_tag) BOOST_PROTO_BINARY_OP(>>, right_shift_tag) BOOST_PROTO_BINARY_OP(*, multiply_tag) BOOST_PROTO_BINARY_OP(/, divide_tag) BOOST_PROTO_BINARY_OP(%, modulus_tag) BOOST_PROTO_BINARY_OP(+, add_tag) BOOST_PROTO_BINARY_OP(-, subtract_tag) BOOST_PROTO_BINARY_OP(<, less_tag) BOOST_PROTO_BINARY_OP(>, greater_tag) BOOST_PROTO_BINARY_OP(<=, less_equal_tag) BOOST_PROTO_BINARY_OP(>=, greater_equal_tag) BOOST_PROTO_BINARY_OP(==, equal_tag) BOOST_PROTO_BINARY_OP(!=, not_equal_tag) BOOST_PROTO_BINARY_OP(||, logical_or_tag) BOOST_PROTO_BINARY_OP(&&, logical_and_tag) BOOST_PROTO_BINARY_OP(&, bitand_tag) BOOST_PROTO_BINARY_OP(|, bitor_tag) BOOST_PROTO_BINARY_OP(^, bitxor_tag) BOOST_PROTO_BINARY_OP(BOOST_PP_COMMA(), comma_tag) BOOST_PROTO_BINARY_OP(->*, mem_ptr_tag) BOOST_PROTO_BINARY_OP(<<=, left_shift_assign_tag) BOOST_PROTO_BINARY_OP(>>=, right_shift_assign_tag) BOOST_PROTO_BINARY_OP(*=, multiply_assign_tag) BOOST_PROTO_BINARY_OP(/=, divide_assign_tag) BOOST_PROTO_BINARY_OP(%=, modulus_assign_tag) BOOST_PROTO_BINARY_OP(+=, add_assign_tag) BOOST_PROTO_BINARY_OP(-=, subtract_assign_tag) BOOST_PROTO_BINARY_OP(&=, bitand_assign_tag) BOOST_PROTO_BINARY_OP(|=, bitor_assign_tag) BOOST_PROTO_BINARY_OP(^=, bitxor_assign_tag) #undef BOOST_PROTO_BINARY_OP #undef BOOST_PROTO_UNARY_OP /////////////////////////////////////////////////////////////////////////////// // post-fix operators template inline typename lazy_enable_if, unary_op_generator >::type const operator ++(Arg const &arg, int) { return make_op(arg.cast()); } template inline typename lazy_enable_if, unary_op_generator >::type const operator --(Arg const &arg, int) { return make_op(arg.cast()); } }} #endif