File: user_macros_snippets.cpp

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (376 lines) | stat: -rw-r--r-- 8,703 bytes parent folder | download | duplicates (6)
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
// 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)
#include <boost/yap/expression.hpp>

#include <string>
#include <vector>


#define user_expr user_expr_1

/// [USER_UNARY_OPERATOR]
template <boost::yap::expr_kind Kind, typename Tuple>
struct user_expr
{
    static const boost::yap::expr_kind kind = Kind;

    Tuple elements;
};

// Operator overloads for operator!().
BOOST_YAP_USER_UNARY_OPERATOR(logical_not, user_expr, user_expr)
/// [USER_UNARY_OPERATOR]

struct lazy_vector_1 :
    user_expr<
        boost::yap::expr_kind::terminal,
        boost::hana::tuple<std::vector<double>>
    >
{};

#undef user_expr

#define user_expr user_expr_2

/// [USER_BINARY_OPERATOR]
template <boost::yap::expr_kind Kind, typename Tuple>
struct user_expr
{
    static const boost::yap::expr_kind kind = Kind;

    Tuple elements;
};

// Operator overloads for operator&&()
BOOST_YAP_USER_BINARY_OPERATOR(logical_and, user_expr, user_expr)
/// [USER_BINARY_OPERATOR]

struct lazy_vector_2 :
    user_expr<
        boost::yap::expr_kind::terminal,
        boost::hana::tuple<std::vector<double>>
    >
{};

#undef user_expr

#define user_expr user_expr_3

/// [USER_CALL_OPERATOR]
template <boost::yap::expr_kind Kind, typename Tuple>
struct user_expr
{
    static const boost::yap::expr_kind kind = Kind;

    Tuple elements;

    // Member operator overloads for operator()().  These will match any
    // number of parameters.  Each one can be any type, even another
    // expression.
    BOOST_YAP_USER_CALL_OPERATOR(::user_expr)
};
/// [USER_CALL_OPERATOR]

struct lazy_vector_3 :
    user_expr<
        boost::yap::expr_kind::terminal,
        boost::hana::tuple<std::vector<double>>
    >
{};

#undef user_expr

#define user_expr user_expr_4

/// [USER_SUBSCRIPT_OPERATOR]
template <boost::yap::expr_kind Kind, typename Tuple>
struct user_expr
{
    static const boost::yap::expr_kind kind = Kind;

    Tuple elements;

    // Member operator overloads for operator[]().  These will match any value
    // on the right-hand side, even another expression.
    BOOST_YAP_USER_SUBSCRIPT_OPERATOR(::user_expr)
};

/// [USER_SUBSCRIPT_OPERATOR]

struct lazy_vector_4 :
    user_expr<
        boost::yap::expr_kind::terminal,
        boost::hana::tuple<std::vector<double>>
    >
{};

#undef user_expr

#define user_expr user_expr_5

/// [USER_EXPR_IF_ELSE]
template <boost::yap::expr_kind Kind, typename Tuple>
struct user_expr
{
    static const boost::yap::expr_kind kind = Kind;

    Tuple elements;
};

// Defines an overload of if_else() that returns expressions instantiated from
// user_expr.
BOOST_YAP_USER_EXPR_IF_ELSE(::user_expr)
/// [USER_EXPR_IF_ELSE]

struct lazy_vector_5 :
    user_expr<
        boost::yap::expr_kind::terminal,
        boost::hana::tuple<std::vector<double>>
    >
{};

#undef user_expr

#define user_expr user_expr_6
#define is_vector is_vector_1

/// [USER_UDT_ANY_IF_ELSE]
template <boost::yap::expr_kind Kind, typename Tuple>
struct user_expr
{
    static const boost::yap::expr_kind kind = Kind;

    Tuple elements;
};

template <typename T>
struct is_vector : std::false_type {};

template <typename T, typename A>
struct is_vector<std::vector<T, A>> : std::true_type {};

// Defines an overload of if_else() that returns expressions instantiated from
// user_expr.
BOOST_YAP_USER_UDT_ANY_IF_ELSE(::user_expr, is_vector)
/// [USER_UDT_ANY_IF_ELSE]

struct lazy_vector_6 :
    user_expr<
        boost::yap::expr_kind::terminal,
        boost::hana::tuple<std::vector<double>>
    >
{};

#undef is_vector
#undef user_expr

#define user_expr user_expr_7
#define is_vector is_vector_2

/// [USER_UDT_UNARY_OPERATOR]
template <boost::yap::expr_kind Kind, typename Tuple>
struct user_expr
{
    static const boost::yap::expr_kind kind = Kind;

    Tuple elements;
};

template <typename T>
struct is_vector : std::false_type {};

template <typename T, typename A>
struct is_vector<std::vector<T, A>> : std::true_type {};

// Defines an overload of operator!() that applies to vectors and returns
// expressions instantiated from user_expr.
BOOST_YAP_USER_UDT_UNARY_OPERATOR(logical_not, ::user_expr, is_vector)
/// [USER_UDT_UNARY_OPERATOR]

struct lazy_vector_7 :
    user_expr<
        boost::yap::expr_kind::terminal,
        boost::hana::tuple<std::vector<double>>
    >
{};

#undef is_vector
#undef user_expr

#define user_expr user_expr_8
#define is_vector is_vector_3

/// [USER_UDT_UDT_BINARY_OPERATOR]
template <boost::yap::expr_kind Kind, typename Tuple>
struct user_expr
{
    static const boost::yap::expr_kind kind = Kind;

    Tuple elements;
};

template <typename T>
struct is_vector : std::false_type {};

template <typename T, typename A>
struct is_vector<std::vector<T, A>> : std::true_type {};

template <typename T>
struct is_string : std::false_type {};

template <>
struct is_string<std::string> : std::true_type {};

// Defines an overload of operator||() that applies to vectors on the left and
// strings on the right, and returns expressions instantiated from user_expr.
BOOST_YAP_USER_UDT_UDT_BINARY_OPERATOR(logical_or, ::user_expr, is_vector, is_string)

// Defines an overload of operator&&() that applies to strings and returns
// expressions instantiated from user_expr.
BOOST_YAP_USER_UDT_UDT_BINARY_OPERATOR(logical_and, ::user_expr, is_string, is_string)
/// [USER_UDT_UDT_BINARY_OPERATOR]

struct lazy_vector_8 :
    user_expr<
        boost::yap::expr_kind::terminal,
        boost::hana::tuple<std::vector<double>>
    >
{};

#undef is_vector
#undef user_expr

#define user_expr user_expr_9
#define is_vector is_vector_4

/// [USER_UDT_ANY_BINARY_OPERATOR]
template <boost::yap::expr_kind Kind, typename Tuple>
struct user_expr
{
    static const boost::yap::expr_kind kind = Kind;

    Tuple elements;
};

template <typename T>
struct is_vector : std::false_type {};

template <typename T, typename A>
struct is_vector<std::vector<T, A>> : std::true_type {};

// Defines an overload of operator&&() that matches a vector on either side,
// and any type (possibly a vector) on the other.
BOOST_YAP_USER_UDT_ANY_BINARY_OPERATOR(logical_and, ::user_expr, is_vector)
/// [USER_UDT_ANY_BINARY_OPERATOR]

struct lazy_vector_9 :
    user_expr<
        boost::yap::expr_kind::terminal,
        boost::hana::tuple<std::vector<double>>
    >
{};

#undef is_vector
#undef user_expr

#define user_expr user_expr_10

/// [USER_LITERAL_PLACEHOLDER_OPERATOR]
template <boost::yap::expr_kind Kind, typename Tuple>
struct user_expr
{
    static const boost::yap::expr_kind kind = Kind;

    Tuple elements;
};

namespace literals {

    // Defines a user literal operator that makes placeholders; 2_p will be a
    // 2-placeholder instantiated from the user_expr template.
    BOOST_YAP_USER_LITERAL_PLACEHOLDER_OPERATOR(user_expr)

}
/// [USER_LITERAL_PLACEHOLDER_OPERATOR]

struct lazy_vector_10 :
    user_expr<
        boost::yap::expr_kind::terminal,
        boost::hana::tuple<std::vector<double>>
    >
{};

#undef user_expr

#define user_expr user_expr_11

/// [USER_ASSIGN_OPERATOR]
template <boost::yap::expr_kind Kind, typename Tuple>
struct user_expr
{
    static const boost::yap::expr_kind kind = Kind;

    Tuple elements;

    // Member operator overloads for operator=().  These will match any value
    // on the right-hand side, even another expression, except that it will
    // not conflict with the asignment or move assignment operators.
    BOOST_YAP_USER_ASSIGN_OPERATOR(user_expr, ::user_expr)
};
/// [USER_ASSIGN_OPERATOR]

struct lazy_vector_11 :
    user_expr<
        boost::yap::expr_kind::terminal,
        boost::hana::tuple<std::vector<double>>
    >
{};

#undef user_expr

#undef user_expr

#define user_expr user_expr_12

/// [USER_CALL_OPERATOR]
template <boost::yap::expr_kind Kind, typename Tuple>
struct user_expr
{
    static const boost::yap::expr_kind kind = Kind;

    Tuple elements;

    // Member operator overloads for operator()().  These will take exactly N
    // parameters.  Each one can be any type, even another expression.
    BOOST_YAP_USER_CALL_OPERATOR(::user_expr)
};
/// [USER_CALL_OPERATOR]

struct lazy_vector_12 :
    user_expr<
        boost::yap::expr_kind::terminal,
        boost::hana::tuple<std::vector<double>>
    >
{};


int main ()
{
    lazy_vector_1 v1;
    lazy_vector_2 v2;
    lazy_vector_3 v3;
    lazy_vector_4 v4;
    lazy_vector_5 v5;
    lazy_vector_6 v6;
    lazy_vector_7 v7;
    lazy_vector_8 v8;
    lazy_vector_9 v9;
    lazy_vector_10 v10;
    lazy_vector_11 v11;
    lazy_vector_12 v12;

    return 0;
}