1 | /////////////////////////////////////////////////////////////////////////////// |
---|
2 | /// \file operators.hpp |
---|
3 | /// Contains all the overloaded operators that make it possible to build |
---|
4 | /// expression templates using proto components |
---|
5 | // |
---|
6 | // Copyright 2004 Eric Niebler. Distributed under the Boost |
---|
7 | // Software License, Version 1.0. (See accompanying file |
---|
8 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
9 | |
---|
10 | #ifndef BOOST_PROTO_OPERATORS_HPP_EAN_04_01_2005 |
---|
11 | #define BOOST_PROTO_OPERATORS_HPP_EAN_04_01_2005 |
---|
12 | |
---|
13 | #include <boost/mpl/or.hpp> |
---|
14 | #include <boost/utility/enable_if.hpp> |
---|
15 | #include <boost/preprocessor/punctuation/comma.hpp> |
---|
16 | #include <boost/xpressive/proto/proto_fwd.hpp> |
---|
17 | #include <boost/xpressive/proto/op_tags.hpp> |
---|
18 | #include <boost/xpressive/proto/op_base.hpp> |
---|
19 | |
---|
20 | namespace boost { namespace proto |
---|
21 | { |
---|
22 | /////////////////////////////////////////////////////////////////////////////// |
---|
23 | // unary_op_generator |
---|
24 | template<typename Arg, typename Tag> |
---|
25 | struct unary_op_generator |
---|
26 | { |
---|
27 | typedef unary_op< |
---|
28 | typename as_op<Arg>::type |
---|
29 | , Tag |
---|
30 | > type; |
---|
31 | }; |
---|
32 | |
---|
33 | /////////////////////////////////////////////////////////////////////////////// |
---|
34 | // binary_op_generator |
---|
35 | template<typename Left, typename Right, typename Tag> |
---|
36 | struct binary_op_generator |
---|
37 | { |
---|
38 | typedef binary_op< |
---|
39 | typename as_op<Left>::type |
---|
40 | , typename as_op<Right>::type |
---|
41 | , Tag |
---|
42 | > type; |
---|
43 | }; |
---|
44 | |
---|
45 | /////////////////////////////////////////////////////////////////////////////// |
---|
46 | // unary operators |
---|
47 | template<typename Arg> |
---|
48 | unary_op<Arg, noop_tag> const |
---|
49 | noop(Arg const &arg) |
---|
50 | { |
---|
51 | return make_op<noop_tag>(arg); |
---|
52 | } |
---|
53 | |
---|
54 | #define BOOST_PROTO_UNARY_OP(op, tag) \ |
---|
55 | template<typename Arg> \ |
---|
56 | inline typename lazy_enable_if<is_op<Arg>, unary_op_generator<Arg, tag> >::type const \ |
---|
57 | operator op(Arg const &arg) \ |
---|
58 | { \ |
---|
59 | return make_op<tag>(as_op<Arg>::make(arg)); \ |
---|
60 | } |
---|
61 | |
---|
62 | #define BOOST_PROTO_BINARY_OP(op, tag) \ |
---|
63 | template<typename Left, typename Right> \ |
---|
64 | inline typename lazy_enable_if< \ |
---|
65 | mpl::or_<is_op<Left>, is_op<Right> > \ |
---|
66 | , binary_op_generator<Left, Right, tag> \ |
---|
67 | >::type const \ |
---|
68 | operator op(Left const &left, Right const &right) \ |
---|
69 | { \ |
---|
70 | return make_op<tag>(as_op<Left>::make(left), as_op<Right>::make(right)); \ |
---|
71 | } |
---|
72 | |
---|
73 | BOOST_PROTO_UNARY_OP(+, unary_plus_tag) |
---|
74 | BOOST_PROTO_UNARY_OP(-, unary_minus_tag) |
---|
75 | BOOST_PROTO_UNARY_OP(*, unary_star_tag) |
---|
76 | BOOST_PROTO_UNARY_OP(~, complement_tag) |
---|
77 | BOOST_PROTO_UNARY_OP(&, address_of_tag) |
---|
78 | BOOST_PROTO_UNARY_OP(!, logical_not_tag) |
---|
79 | BOOST_PROTO_UNARY_OP(++, pre_inc_tag) |
---|
80 | BOOST_PROTO_UNARY_OP(--, pre_dec_tag) |
---|
81 | |
---|
82 | BOOST_PROTO_BINARY_OP(<<, left_shift_tag) |
---|
83 | BOOST_PROTO_BINARY_OP(>>, right_shift_tag) |
---|
84 | BOOST_PROTO_BINARY_OP(*, multiply_tag) |
---|
85 | BOOST_PROTO_BINARY_OP(/, divide_tag) |
---|
86 | BOOST_PROTO_BINARY_OP(%, modulus_tag) |
---|
87 | BOOST_PROTO_BINARY_OP(+, add_tag) |
---|
88 | BOOST_PROTO_BINARY_OP(-, subtract_tag) |
---|
89 | BOOST_PROTO_BINARY_OP(<, less_tag) |
---|
90 | BOOST_PROTO_BINARY_OP(>, greater_tag) |
---|
91 | BOOST_PROTO_BINARY_OP(<=, less_equal_tag) |
---|
92 | BOOST_PROTO_BINARY_OP(>=, greater_equal_tag) |
---|
93 | BOOST_PROTO_BINARY_OP(==, equal_tag) |
---|
94 | BOOST_PROTO_BINARY_OP(!=, not_equal_tag) |
---|
95 | BOOST_PROTO_BINARY_OP(||, logical_or_tag) |
---|
96 | BOOST_PROTO_BINARY_OP(&&, logical_and_tag) |
---|
97 | BOOST_PROTO_BINARY_OP(&, bitand_tag) |
---|
98 | BOOST_PROTO_BINARY_OP(|, bitor_tag) |
---|
99 | BOOST_PROTO_BINARY_OP(^, bitxor_tag) |
---|
100 | BOOST_PROTO_BINARY_OP(BOOST_PP_COMMA(), comma_tag) |
---|
101 | BOOST_PROTO_BINARY_OP(->*, mem_ptr_tag) |
---|
102 | |
---|
103 | BOOST_PROTO_BINARY_OP(<<=, left_shift_assign_tag) |
---|
104 | BOOST_PROTO_BINARY_OP(>>=, right_shift_assign_tag) |
---|
105 | BOOST_PROTO_BINARY_OP(*=, multiply_assign_tag) |
---|
106 | BOOST_PROTO_BINARY_OP(/=, divide_assign_tag) |
---|
107 | BOOST_PROTO_BINARY_OP(%=, modulus_assign_tag) |
---|
108 | BOOST_PROTO_BINARY_OP(+=, add_assign_tag) |
---|
109 | BOOST_PROTO_BINARY_OP(-=, subtract_assign_tag) |
---|
110 | BOOST_PROTO_BINARY_OP(&=, bitand_assign_tag) |
---|
111 | BOOST_PROTO_BINARY_OP(|=, bitor_assign_tag) |
---|
112 | BOOST_PROTO_BINARY_OP(^=, bitxor_assign_tag) |
---|
113 | |
---|
114 | #undef BOOST_PROTO_BINARY_OP |
---|
115 | #undef BOOST_PROTO_UNARY_OP |
---|
116 | |
---|
117 | /////////////////////////////////////////////////////////////////////////////// |
---|
118 | // post-fix operators |
---|
119 | template<typename Arg> |
---|
120 | inline typename lazy_enable_if<is_op<Arg>, unary_op_generator<Arg, post_inc_tag> >::type const |
---|
121 | operator ++(Arg const &arg, int) |
---|
122 | { |
---|
123 | return make_op<post_inc_tag>(arg.cast()); |
---|
124 | } |
---|
125 | |
---|
126 | template<typename Arg> |
---|
127 | inline typename lazy_enable_if<is_op<Arg>, unary_op_generator<Arg, post_dec_tag> >::type const |
---|
128 | operator --(Arg const &arg, int) |
---|
129 | { |
---|
130 | return make_op<post_dec_tag>(arg.cast()); |
---|
131 | } |
---|
132 | |
---|
133 | }} |
---|
134 | |
---|
135 | #endif |
---|