liuxiaolong
2021-07-20 58d904a328c0d849769b483e901a0be9426b8209
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
// Copyright (C) 2016-2018 T. Zachary Laine
//
// 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_YAP_EXPRESSION_HPP_INCLUDED
#define BOOST_YAP_EXPRESSION_HPP_INCLUDED
 
#include <boost/yap/algorithm.hpp>
 
 
namespace boost { namespace yap {
 
    /** Reference expression template that provides all operator overloads.
 
        \note Due to a limitation of Doxygen, each of the
        <code>value()</code>, <code>left()</code>, <code>right()</code>, and
        operator overloads listed here is a stand-in for three member
        functions.  For each function <code>f</code>, the listing here is:
        \code return_type f (); \endcode  However, there are actually three
        functions:
        \code
        return_type f () const &;
        return_type f () &;
        return_type f () &&;
        \endcode
    */
    template<expr_kind Kind, typename Tuple>
    struct expression
    {
        using tuple_type = Tuple;
 
        static const expr_kind kind = Kind;
 
        /** Default constructor.  Does nothing. */
        constexpr expression() {}
 
        /** Moves \a rhs into the only data mamber, \c elements. */
        constexpr expression(tuple_type && rhs) :
            elements(static_cast<tuple_type &&>(rhs))
        {}
 
        tuple_type elements;
 
        /** A convenience member function that dispatches to the free function
            <code>value()</code>. */
        constexpr decltype(auto) value() &
        {
            return ::boost::yap::value(*this);
        }
 
#ifndef BOOST_YAP_DOXYGEN
 
        constexpr decltype(auto) value() const &
        {
            return ::boost::yap::value(*this);
        }
 
        constexpr decltype(auto) value() &&
        {
            return ::boost::yap::value(std::move(*this));
        }
 
#endif
 
        /** A convenience member function that dispatches to the free function
            <code>left()</code>. */
        constexpr decltype(auto) left() & { return ::boost::yap::left(*this); }
 
#ifndef BOOST_YAP_DOXYGEN
 
        constexpr decltype(auto) left() const &
        {
            return ::boost::yap::left(*this);
        }
 
        constexpr decltype(auto) left() &&
        {
            return ::boost::yap::left(std::move(*this));
        }
 
#endif
 
        /** A convenience member function that dispatches to the free function
            <code>right()</code>. */
        constexpr decltype(auto) right() &
        {
            return ::boost::yap::right(*this);
        }
 
#ifndef BOOST_YAP_DOXYGEN
 
        constexpr decltype(auto) right() const &
        {
            return ::boost::yap::right(*this);
        }
 
        constexpr decltype(auto) right() &&
        {
            return ::boost::yap::right(std::move(*this));
        }
 
#endif
 
        BOOST_YAP_USER_ASSIGN_OPERATOR(
            expression, ::boost::yap::expression)                   // =
        BOOST_YAP_USER_SUBSCRIPT_OPERATOR(::boost::yap::expression) // []
        BOOST_YAP_USER_CALL_OPERATOR(::boost::yap::expression)      // ()
    };
 
    /** Terminal expression specialization of the reference expression
        template.
 
        \note Due to a limitation of Doxygen, the <code>value()</code> member
        and each of the operator overloads listed here is a stand-in for three
        member functions.  For each function <code>f</code>, the listing here
        is: \code return_type f (); \endcode However, there are actually three
        functions:
        \code
        return_type f () const &;
        return_type f () &;
        return_type f () &&;
        \endcode
    */
    template<typename T>
    struct expression<expr_kind::terminal, hana::tuple<T>>
    {
        using tuple_type = hana::tuple<T>;
 
        static const expr_kind kind = expr_kind::terminal;
 
        /** Default constructor.  Does nothing. */
        constexpr expression() {}
 
        /** Forwards \a t into \c elements. */
        constexpr expression(T && t) : elements(static_cast<T &&>(t)) {}
 
        /** Copies \a rhs into the only data mamber, \c elements. */
        constexpr expression(hana::tuple<T> const & rhs) : elements(rhs) {}
 
        /** Moves \a rhs into the only data mamber, \c elements. */
        constexpr expression(hana::tuple<T> && rhs) : elements(std::move(rhs))
        {}
 
        tuple_type elements;
 
        /** A convenience member function that dispatches to the free function
            <code>value()</code>. */
        constexpr decltype(auto) value() &
        {
            return ::boost::yap::value(*this);
        }
 
#ifndef BOOST_YAP_DOXYGEN
 
        constexpr decltype(auto) value() const &
        {
            return ::boost::yap::value(*this);
        }
 
        constexpr decltype(auto) value() &&
        {
            return ::boost::yap::value(std::move(*this));
        }
 
#endif
 
        BOOST_YAP_USER_ASSIGN_OPERATOR(
            expression, ::boost::yap::expression)                   // =
        BOOST_YAP_USER_SUBSCRIPT_OPERATOR(::boost::yap::expression) // []
        BOOST_YAP_USER_CALL_OPERATOR(::boost::yap::expression)      // ()
    };
 
#ifndef BOOST_YAP_DOXYGEN
 
    BOOST_YAP_USER_UNARY_OPERATOR(unary_plus, expression, expression)  // +
    BOOST_YAP_USER_UNARY_OPERATOR(negate, expression, expression)      // -
    BOOST_YAP_USER_UNARY_OPERATOR(dereference, expression, expression) // *
    BOOST_YAP_USER_UNARY_OPERATOR(complement, expression, expression)  // ~
    BOOST_YAP_USER_UNARY_OPERATOR(address_of, expression, expression)  // &
    BOOST_YAP_USER_UNARY_OPERATOR(logical_not, expression, expression) // !
    BOOST_YAP_USER_UNARY_OPERATOR(pre_inc, expression, expression)     // ++
    BOOST_YAP_USER_UNARY_OPERATOR(pre_dec, expression, expression)     // --
    BOOST_YAP_USER_UNARY_OPERATOR(post_inc, expression, expression)    // ++(int)
    BOOST_YAP_USER_UNARY_OPERATOR(post_dec, expression, expression)    // --(int)
 
    BOOST_YAP_USER_BINARY_OPERATOR(shift_left, expression, expression)         // <<
    BOOST_YAP_USER_BINARY_OPERATOR(shift_right, expression, expression)        // >>
    BOOST_YAP_USER_BINARY_OPERATOR(multiplies, expression, expression)         // *
    BOOST_YAP_USER_BINARY_OPERATOR(divides, expression, expression)            // /
    BOOST_YAP_USER_BINARY_OPERATOR(modulus, expression, expression)            // %
    BOOST_YAP_USER_BINARY_OPERATOR(plus, expression, expression)               // +
    BOOST_YAP_USER_BINARY_OPERATOR(minus, expression, expression)              // -
    BOOST_YAP_USER_BINARY_OPERATOR(less, expression, expression)               // <
    BOOST_YAP_USER_BINARY_OPERATOR(greater, expression, expression)            // >
    BOOST_YAP_USER_BINARY_OPERATOR(less_equal, expression, expression)         // <=
    BOOST_YAP_USER_BINARY_OPERATOR(greater_equal, expression, expression)      // >=
    BOOST_YAP_USER_BINARY_OPERATOR(equal_to, expression, expression)           // ==
    BOOST_YAP_USER_BINARY_OPERATOR(not_equal_to, expression, expression)       // !=
    BOOST_YAP_USER_BINARY_OPERATOR(logical_or, expression, expression)         // ||
    BOOST_YAP_USER_BINARY_OPERATOR(logical_and, expression, expression)        // &&
    BOOST_YAP_USER_BINARY_OPERATOR(bitwise_and, expression, expression)        // &
    BOOST_YAP_USER_BINARY_OPERATOR(bitwise_or, expression, expression)         // |
    BOOST_YAP_USER_BINARY_OPERATOR(bitwise_xor, expression, expression)        // ^
    BOOST_YAP_USER_BINARY_OPERATOR(comma, expression, expression)              // ,
    BOOST_YAP_USER_BINARY_OPERATOR(mem_ptr, expression, expression)            // ->*
    BOOST_YAP_USER_BINARY_OPERATOR(shift_left_assign, expression, expression)  // <<=
    BOOST_YAP_USER_BINARY_OPERATOR(shift_right_assign, expression, expression) // >>=
    BOOST_YAP_USER_BINARY_OPERATOR(multiplies_assign, expression, expression)  // *=
    BOOST_YAP_USER_BINARY_OPERATOR(divides_assign, expression, expression)     // /=
    BOOST_YAP_USER_BINARY_OPERATOR(modulus_assign, expression, expression)     // %=
    BOOST_YAP_USER_BINARY_OPERATOR(plus_assign, expression, expression)        // +=
    BOOST_YAP_USER_BINARY_OPERATOR(minus_assign, expression, expression)       // -=
    BOOST_YAP_USER_BINARY_OPERATOR(bitwise_and_assign, expression, expression) // &=
    BOOST_YAP_USER_BINARY_OPERATOR(bitwise_or_assign, expression, expression)  // |=
    BOOST_YAP_USER_BINARY_OPERATOR(bitwise_xor_assign, expression, expression) // ^=
 
    BOOST_YAP_USER_EXPR_IF_ELSE(expression)
 
#else
 
    /** \see BOOST_YAP_USER_UNARY_OPERATOR for full semantics. */
    template<typename Expr>
    constexpr auto operator+(Expr &&);
    /** \see BOOST_YAP_USER_UNARY_OPERATOR for full semantics. */
    template<typename Expr>
    constexpr auto operator-(Expr &&);
    /** \see BOOST_YAP_USER_UNARY_OPERATOR for full semantics. */
    template<typename Expr>
    constexpr auto operator*(Expr &&);
    /** \see BOOST_YAP_USER_UNARY_OPERATOR for full semantics. */
    template<typename Expr>
    constexpr auto operator~(Expr &&);
    /** \see BOOST_YAP_USER_UNARY_OPERATOR for full semantics. */
    template<typename Expr>
    constexpr auto operator&(Expr &&);
    /** \see BOOST_YAP_USER_UNARY_OPERATOR for full semantics. */
    template<typename Expr>
    constexpr auto operator!(Expr &&);
    /** \see BOOST_YAP_USER_UNARY_OPERATOR for full semantics. */
    template<typename Expr>
    constexpr auto operator++(Expr &&);
    /** \see BOOST_YAP_USER_UNARY_OPERATOR for full semantics. */
    template<typename Expr>
    constexpr auto operator--(Expr &&);
    /** \see BOOST_YAP_USER_UNARY_OPERATOR for full semantics. */
    template<typename Expr>
    constexpr auto operator++(Expr &&, int);
    /** \see BOOST_YAP_USER_UNARY_OPERATOR for full semantics. */
    template<typename Expr>
    constexpr auto operator--(Expr &&, int);
 
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator<<(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator>>(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator*(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator/(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator%(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator+(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator-(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator<(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator>(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator<=(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator>=(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator==(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator!=(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator||(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator&&(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator&(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator|(LExpr && lhs, RExpr && rhs);
    /** \see BOOST_YAP_USER_BINARY_OPERATOR for full semantics. */
    template<typename LExpr, typename RExpr>
    constexpr auto operator^(LExpr && lhs, RExpr && rhs);
 
    /** \see BOOST_YAP_USER_EXPR_IF_ELSE for full semantics. */
    template<typename Expr1, typename Expr2, typename Expr3>
    constexpr auto if_else(Expr1 && expr1, Expr2 && expr2, Expr3 && expr3);
 
#endif
 
    /** Returns <code>make_expression<boost::yap::expression, Kind>(...)</code>.
     */
    template<expr_kind Kind, typename... T>
    constexpr auto make_expression(T &&... t)
    {
        return make_expression<expression, Kind>(static_cast<T &&>(t)...);
    }
 
    /** Returns <code>make_terminal<boost::yap::expression>(t)</code>. */
    template<typename T>
    constexpr auto make_terminal(T && t)
    {
        return make_terminal<expression>(static_cast<T &&>(t));
    }
 
    /** Returns <code>as_expr<boost::yap::expression>(t)</code>. */
    template<typename T>
    constexpr decltype(auto) as_expr(T && t)
    {
        return as_expr<expression>(static_cast<T &&>(t));
    }
 
}}
 
#endif