~ubuntu-branches/debian/sid/boost1.49/sid

« back to all changes in this revision

Viewing changes to boost/proto/extends.hpp

  • Committer: Package Import Robot
  • Author(s): Steve M. Robbins
  • Date: 2012-02-26 00:31:44 UTC
  • Revision ID: package-import@ubuntu.com-20120226003144-eaytp12cbf6ubpms
Tags: upstream-1.49.0
ImportĀ upstreamĀ versionĀ 1.49.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
///////////////////////////////////////////////////////////////////////////////
 
2
/// \file extends.hpp
 
3
/// Macros and a base class for defining end-user expression types
 
4
//
 
5
//  Copyright 2008 Eric Niebler. Distributed under the Boost
 
6
//  Software License, Version 1.0. (See accompanying file
 
7
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
8
 
 
9
#ifndef BOOST_PROTO_EXTENDS_HPP_EAN_11_1_2006
 
10
#define BOOST_PROTO_EXTENDS_HPP_EAN_11_1_2006
 
11
 
 
12
#include <cstddef> // for offsetof
 
13
#include <boost/config.hpp>
 
14
#include <boost/detail/workaround.hpp>
 
15
#include <boost/preprocessor/facilities/empty.hpp>
 
16
#include <boost/preprocessor/tuple/elem.hpp>
 
17
#include <boost/preprocessor/control/if.hpp>
 
18
#include <boost/preprocessor/arithmetic/inc.hpp>
 
19
#include <boost/preprocessor/arithmetic/dec.hpp>
 
20
#include <boost/preprocessor/iteration/local.hpp>
 
21
#include <boost/preprocessor/repetition/enum_params.hpp>
 
22
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
 
23
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
 
24
#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
 
25
#include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
 
26
#include <boost/preprocessor/seq/for_each.hpp>
 
27
#include <boost/utility/addressof.hpp>
 
28
#include <boost/utility/result_of.hpp>
 
29
#include <boost/proto/proto_fwd.hpp>
 
30
#include <boost/proto/traits.hpp>
 
31
#include <boost/proto/expr.hpp>
 
32
#include <boost/proto/args.hpp>
 
33
#include <boost/proto/traits.hpp>
 
34
#include <boost/proto/generate.hpp>
 
35
#include <boost/proto/detail/remove_typename.hpp>
 
36
 
 
37
#ifdef _MSC_VER
 
38
#define BOOST_PROTO_DISABLE_MSVC_C4522 __pragma(warning(disable: 4522))
 
39
#else
 
40
#define BOOST_PROTO_DISABLE_MSVC_C4522 
 
41
#endif
 
42
 
 
43
namespace boost { namespace proto
 
44
{
 
45
    #ifdef __GNUC__
 
46
    /// INTERNAL ONLY
 
47
    ///
 
48
    # define BOOST_PROTO_ADDROF(x) ((char const volatile*)boost::addressof(x))
 
49
    /// INTERNAL ONLY
 
50
    ///
 
51
    # define BOOST_PROTO_OFFSETOF(s,m) (BOOST_PROTO_ADDROF((((s *)this)->m)) - BOOST_PROTO_ADDROF(*((s *)this)))
 
52
    #else
 
53
    /// INTERNAL ONLY
 
54
    ///
 
55
    # define BOOST_PROTO_OFFSETOF offsetof
 
56
    #endif
 
57
 
 
58
    /// INTERNAL ONLY
 
59
    ///
 
60
    #define BOOST_PROTO_CONST() const
 
61
 
 
62
    /// INTERNAL ONLY
 
63
    ///
 
64
    #define BOOST_PROTO_TYPENAME() typename
 
65
 
 
66
    /// INTERNAL ONLY
 
67
    ///
 
68
    #define BOOST_PROTO_TEMPLATE_YES_(Z, N) template<BOOST_PP_ENUM_PARAMS_Z(Z, N, typename A)>
 
69
 
 
70
    /// INTERNAL ONLY
 
71
    ///
 
72
    #define BOOST_PROTO_TEMPLATE_NO_(Z, N)
 
73
 
 
74
    /// INTERNAL ONLY
 
75
    ///
 
76
    #define BOOST_PROTO_DEFINE_FUN_OP_IMPL_(Z, N, DATA, Const)                                      \
 
77
        BOOST_PP_IF(N, BOOST_PROTO_TEMPLATE_YES_, BOOST_PROTO_TEMPLATE_NO_)(Z, N)                   \
 
78
        BOOST_FORCEINLINE                                                                           \
 
79
        typename BOOST_PROTO_RESULT_OF<                                                             \
 
80
            proto_generator(                                                                        \
 
81
                typename boost::proto::result_of::BOOST_PP_CAT(funop, N)<                           \
 
82
                    proto_derived_expr Const()                                                      \
 
83
                  , proto_domain                                                                    \
 
84
                    BOOST_PP_ENUM_TRAILING_PARAMS_Z(Z, N, const A)                                  \
 
85
                >::type                                                                             \
 
86
            )                                                                                       \
 
87
        >::type const                                                                               \
 
88
        operator ()(BOOST_PP_ENUM_BINARY_PARAMS_Z(Z, N, A, const &a)) Const()                       \
 
89
        {                                                                                           \
 
90
            typedef boost::proto::result_of::BOOST_PP_CAT(funop, N)<                                \
 
91
                proto_derived_expr Const()                                                          \
 
92
              , proto_domain                                                                        \
 
93
                BOOST_PP_ENUM_TRAILING_PARAMS_Z(Z, N, const A)                                      \
 
94
            > funop;                                                                                \
 
95
            return proto_generator()(                                                               \
 
96
                funop::call(                                                                        \
 
97
                    *static_cast<proto_derived_expr Const() *>(this)                                \
 
98
                    BOOST_PP_ENUM_TRAILING_PARAMS_Z(Z, N, a)                                        \
 
99
                )                                                                                   \
 
100
            );                                                                                      \
 
101
        }                                                                                           \
 
102
        /**/
 
103
 
 
104
    /// INTERNAL ONLY
 
105
    ///
 
106
    #define BOOST_PROTO_DEFINE_FUN_OP_VARIADIC_IMPL_(Const)                                         \
 
107
        template<typename... A>                                                                     \
 
108
        BOOST_FORCEINLINE                                                                           \
 
109
        typename BOOST_PROTO_RESULT_OF<                                                             \
 
110
            proto_generator(                                                                        \
 
111
                typename boost::proto::result_of::funop<                                            \
 
112
                    proto_derived_expr Const()(A const &...)                                        \
 
113
                  , proto_derived_expr                                                              \
 
114
                  , proto_domain                                                                    \
 
115
                >::type                                                                             \
 
116
            )                                                                                       \
 
117
        >::type const                                                                               \
 
118
        operator ()(A const &...a) Const()                                                          \
 
119
        {                                                                                           \
 
120
            typedef boost::proto::result_of::funop<                                                 \
 
121
                proto_derived_expr Const()(A const &...)                                            \
 
122
              , proto_derived_expr                                                                  \
 
123
              , proto_domain                                                                        \
 
124
            > funop;                                                                                \
 
125
            return proto_generator()(                                                               \
 
126
                funop::call(                                                                        \
 
127
                    *static_cast<proto_derived_expr Const() *>(this)                                \
 
128
                  , a...                                                                            \
 
129
                )                                                                                   \
 
130
            );                                                                                      \
 
131
        }                                                                                           \
 
132
        /**/
 
133
 
 
134
    /// INTERNAL ONLY
 
135
    ///
 
136
    #define BOOST_PROTO_DEFINE_FUN_OP_CONST(Z, N, DATA)                                             \
 
137
        BOOST_PROTO_DEFINE_FUN_OP_IMPL_(Z, N, DATA, BOOST_PROTO_CONST)                              \
 
138
        /**/
 
139
 
 
140
    /// INTERNAL ONLY
 
141
    ///
 
142
    #define BOOST_PROTO_DEFINE_FUN_OP_NON_CONST(Z, N, DATA)                                         \
 
143
        BOOST_PROTO_DEFINE_FUN_OP_IMPL_(Z, N, DATA, BOOST_PP_EMPTY)                                 \
 
144
        /**/
 
145
 
 
146
    /// INTERNAL ONLY
 
147
    ///
 
148
    #define BOOST_PROTO_DEFINE_FUN_OP(Z, N, DATA)                                                   \
 
149
        BOOST_PROTO_DEFINE_FUN_OP_CONST(Z, N, DATA)                                                 \
 
150
        BOOST_PROTO_DEFINE_FUN_OP_NON_CONST(Z, N, DATA)                                             \
 
151
        /**/
 
152
 
 
153
    /// INTERNAL ONLY
 
154
    ///
 
155
    #define BOOST_PROTO_EXTENDS_CHILD(Z, N, DATA)                                                   \
 
156
        typedef                                                                                     \
 
157
            typename proto_base_expr::BOOST_PP_CAT(proto_child, N)                                  \
 
158
        BOOST_PP_CAT(proto_child, N);                                                               \
 
159
        /**/
 
160
 
 
161
    #define BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, Domain)                                       \
 
162
        Expr proto_expr_;                                                                           \
 
163
                                                                                                    \
 
164
        typedef Expr proto_base_expr_; /**< INTERNAL ONLY */                                        \
 
165
        typedef typename proto_base_expr_::proto_base_expr proto_base_expr;                         \
 
166
        typedef BOOST_PROTO_REMOVE_TYPENAME(Domain) proto_domain;                                   \
 
167
        typedef Derived proto_derived_expr;                                                         \
 
168
        typedef Domain::proto_generator proto_generator;                                            \
 
169
        typedef typename proto_base_expr::proto_tag proto_tag;                                      \
 
170
        typedef typename proto_base_expr::proto_args proto_args;                                    \
 
171
        typedef typename proto_base_expr::proto_arity proto_arity;                                  \
 
172
        typedef typename proto_base_expr::proto_grammar proto_grammar;                              \
 
173
        typedef typename proto_base_expr::address_of_hack_type_ proto_address_of_hack_type_;        \
 
174
        typedef void proto_is_expr_; /**< INTERNAL ONLY */                                          \
 
175
        static const long proto_arity_c = proto_base_expr::proto_arity_c;                           \
 
176
        typedef boost::proto::tag::proto_expr fusion_tag;                                           \
 
177
        BOOST_PP_REPEAT(BOOST_PROTO_MAX_ARITY, BOOST_PROTO_EXTENDS_CHILD, ~)                        \
 
178
                                                                                                    \
 
179
        BOOST_FORCEINLINE                                                                           \
 
180
        static proto_derived_expr const make(Expr const &e)                                         \
 
181
        {                                                                                           \
 
182
            proto_derived_expr that = {e};                                                          \
 
183
            return that;                                                                            \
 
184
        }                                                                                           \
 
185
                                                                                                    \
 
186
        BOOST_FORCEINLINE                                                                           \
 
187
        proto_base_expr &proto_base()                                                               \
 
188
        {                                                                                           \
 
189
            return this->proto_expr_.proto_base();                                                  \
 
190
        }                                                                                           \
 
191
                                                                                                    \
 
192
        BOOST_FORCEINLINE                                                                           \
 
193
        proto_base_expr const &proto_base() const                                                   \
 
194
        {                                                                                           \
 
195
            return this->proto_expr_.proto_base();                                                  \
 
196
        }                                                                                           \
 
197
                                                                                                    \
 
198
        BOOST_FORCEINLINE                                                                           \
 
199
        operator proto_address_of_hack_type_() const                                                \
 
200
        {                                                                                           \
 
201
            return boost::addressof(this->proto_base().child0);                                     \
 
202
        }                                                                                           \
 
203
        /**/
 
204
 
 
205
    #define BOOST_PROTO_BASIC_EXTENDS(Expr, Derived, Domain)                                        \
 
206
        BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, Domain)                                           \
 
207
        typedef void proto_is_aggregate_;                                                           \
 
208
        /**< INTERNAL ONLY */
 
209
 
 
210
    #define BOOST_PROTO_EXTENDS_COPY_ASSIGN_IMPL_(This, Const, Typename)                            \
 
211
        BOOST_PROTO_DISABLE_MSVC_C4522                                                              \
 
212
        BOOST_FORCEINLINE                                                                           \
 
213
        Typename() BOOST_PROTO_RESULT_OF<                                                           \
 
214
            Typename() This::proto_generator(                                                       \
 
215
                Typename() boost::proto::base_expr<                                                 \
 
216
                    Typename() This::proto_domain                                                   \
 
217
                  , boost::proto::tag::assign                                                       \
 
218
                  , boost::proto::list2<                                                            \
 
219
                        This &                                                                      \
 
220
                      , This Const() &                                                              \
 
221
                    >                                                                               \
 
222
                >::type                                                                             \
 
223
            )                                                                                       \
 
224
        >::type const                                                                               \
 
225
        operator =(This Const() &a)                                                                 \
 
226
        {                                                                                           \
 
227
            typedef                                                                                 \
 
228
                Typename() boost::proto::base_expr<                                                 \
 
229
                    Typename() This::proto_domain                                                   \
 
230
                  , boost::proto::tag::assign                                                       \
 
231
                  , boost::proto::list2<                                                            \
 
232
                        This &                                                                      \
 
233
                      , This Const() &                                                              \
 
234
                    >                                                                               \
 
235
                >::type                                                                             \
 
236
            that_type;                                                                              \
 
237
            that_type const that = {                                                                \
 
238
                *this                                                                               \
 
239
              , a                                                                                   \
 
240
            };                                                                                      \
 
241
            return Typename() This::proto_generator()(that);                                        \
 
242
        }                                                                                           \
 
243
        /**/
 
244
 
 
245
        // MSVC 8.0 and higher seem to need copy-assignment operator to be overloaded on *both*
 
246
        // const and non-const rhs arguments.
 
247
    #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600)) && (BOOST_MSVC > 1310)
 
248
        #define BOOST_PROTO_EXTENDS_COPY_ASSIGN_(This, Typename)                                    \
 
249
            BOOST_PROTO_EXTENDS_COPY_ASSIGN_IMPL_(This, BOOST_PP_EMPTY, Typename)                   \
 
250
            BOOST_PROTO_EXTENDS_COPY_ASSIGN_IMPL_(This, BOOST_PROTO_CONST, Typename)                \
 
251
            /**/
 
252
    #else
 
253
        #define BOOST_PROTO_EXTENDS_COPY_ASSIGN_(This, Typename)                                    \
 
254
            BOOST_PROTO_EXTENDS_COPY_ASSIGN_IMPL_(This, BOOST_PROTO_CONST, Typename)                \
 
255
            /**/
 
256
    #endif
 
257
 
 
258
        /// INTERNAL ONLY
 
259
        ///
 
260
    #define BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(ThisConst, ThatConst)                                  \
 
261
        template<typename A>                                                                        \
 
262
        BOOST_FORCEINLINE                                                                           \
 
263
        typename BOOST_PROTO_RESULT_OF<                                                             \
 
264
            proto_generator(                                                                        \
 
265
                typename boost::proto::base_expr<                                                   \
 
266
                    proto_domain                                                                    \
 
267
                  , boost::proto::tag::assign                                                       \
 
268
                  , boost::proto::list2<                                                            \
 
269
                        proto_derived_expr ThisConst() &                                            \
 
270
                      , typename boost::proto::result_of::as_child<A ThatConst(), proto_domain>::type \
 
271
                    >                                                                               \
 
272
                >::type                                                                             \
 
273
            )                                                                                       \
 
274
        >::type const                                                                               \
 
275
        operator =(A ThatConst() &a) ThisConst()                                                    \
 
276
        {                                                                                           \
 
277
            typedef                                                                                 \
 
278
                typename boost::proto::base_expr<                                                   \
 
279
                    proto_domain                                                                    \
 
280
                  , boost::proto::tag::assign                                                       \
 
281
                  , boost::proto::list2<                                                            \
 
282
                        proto_derived_expr ThisConst() &                                            \
 
283
                      , typename boost::proto::result_of::as_child<A ThatConst(), proto_domain>::type \
 
284
                    >                                                                               \
 
285
                >::type                                                                             \
 
286
            that_type;                                                                              \
 
287
            that_type const that = {                                                                \
 
288
                *static_cast<proto_derived_expr ThisConst() *>(this)                                \
 
289
              , boost::proto::as_child<proto_domain>(a)                                             \
 
290
            };                                                                                      \
 
291
            return proto_generator()(that);                                                         \
 
292
        }                                                                                           \
 
293
        /**/
 
294
 
 
295
    #define BOOST_PROTO_EXTENDS_ASSIGN_CONST_()                                                     \
 
296
        BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(BOOST_PROTO_CONST, BOOST_PP_EMPTY)                         \
 
297
        BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(BOOST_PROTO_CONST, BOOST_PROTO_CONST)                      \
 
298
        /**/
 
299
 
 
300
    #define BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST_()                                                 \
 
301
        BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(BOOST_PP_EMPTY, BOOST_PP_EMPTY)                            \
 
302
        BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(BOOST_PP_EMPTY, BOOST_PROTO_CONST)                         \
 
303
        /**/
 
304
 
 
305
    #define BOOST_PROTO_EXTENDS_ASSIGN_()                                                           \
 
306
        BOOST_PROTO_EXTENDS_ASSIGN_CONST_()                                                         \
 
307
        BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST_()                                                     \
 
308
        /**/
 
309
 
 
310
    #define BOOST_PROTO_EXTENDS_ASSIGN_CONST()                                                      \
 
311
        BOOST_PROTO_EXTENDS_COPY_ASSIGN_(proto_derived_expr, BOOST_PROTO_TYPENAME)                  \
 
312
        BOOST_PROTO_EXTENDS_ASSIGN_CONST_()                                                         \
 
313
        /**/
 
314
 
 
315
    #define BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST()                                                  \
 
316
        BOOST_PROTO_EXTENDS_COPY_ASSIGN_(proto_derived_expr, BOOST_PROTO_TYPENAME)                  \
 
317
        BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST_()                                                     \
 
318
        /**/
 
319
 
 
320
    #define BOOST_PROTO_EXTENDS_ASSIGN()                                                            \
 
321
        BOOST_PROTO_EXTENDS_COPY_ASSIGN_(proto_derived_expr, BOOST_PROTO_TYPENAME)                  \
 
322
        BOOST_PROTO_EXTENDS_ASSIGN_()                                                               \
 
323
        /**/
 
324
 
 
325
        /// INTERNAL ONLY
 
326
        ///
 
327
    #define BOOST_PROTO_EXTENDS_SUBSCRIPT_IMPL_(ThisConst, ThatConst)                               \
 
328
        template<typename A>                                                                        \
 
329
        BOOST_FORCEINLINE                                                                           \
 
330
        typename BOOST_PROTO_RESULT_OF<                                                             \
 
331
            proto_generator(                                                                        \
 
332
                typename boost::proto::base_expr<                                                   \
 
333
                    proto_domain                                                                    \
 
334
                  , boost::proto::tag::subscript                                                    \
 
335
                  , boost::proto::list2<                                                            \
 
336
                        proto_derived_expr ThisConst() &                                            \
 
337
                      , typename boost::proto::result_of::as_child<A ThatConst(), proto_domain>::type \
 
338
                    >                                                                               \
 
339
                >::type                                                                             \
 
340
            )                                                                                       \
 
341
        >::type const                                                                               \
 
342
        operator [](A ThatConst() &a) ThisConst()                                                   \
 
343
        {                                                                                           \
 
344
            typedef                                                                                 \
 
345
                typename boost::proto::base_expr<                                                   \
 
346
                    proto_domain                                                                    \
 
347
                  , boost::proto::tag::subscript                                                    \
 
348
                  , boost::proto::list2<                                                            \
 
349
                        proto_derived_expr ThisConst() &                                            \
 
350
                      , typename boost::proto::result_of::as_child<A ThatConst(), proto_domain>::type \
 
351
                    >                                                                               \
 
352
                >::type                                                                             \
 
353
            that_type;                                                                              \
 
354
            that_type const that = {                                                                \
 
355
                *static_cast<proto_derived_expr ThisConst() *>(this)                                \
 
356
              , boost::proto::as_child<proto_domain>(a)                                             \
 
357
            };                                                                                      \
 
358
            return proto_generator()(that);                                                         \
 
359
        }                                                                                           \
 
360
        /**/
 
361
 
 
362
    #define BOOST_PROTO_EXTENDS_SUBSCRIPT_CONST()                                                   \
 
363
        BOOST_PROTO_EXTENDS_SUBSCRIPT_IMPL_(BOOST_PROTO_CONST, BOOST_PP_EMPTY)                      \
 
364
        BOOST_PROTO_EXTENDS_SUBSCRIPT_IMPL_(BOOST_PROTO_CONST, BOOST_PROTO_CONST)                   \
 
365
        /**/
 
366
 
 
367
    #define BOOST_PROTO_EXTENDS_SUBSCRIPT_NON_CONST()                                               \
 
368
        BOOST_PROTO_EXTENDS_SUBSCRIPT_IMPL_(BOOST_PP_EMPTY, BOOST_PP_EMPTY)                         \
 
369
        BOOST_PROTO_EXTENDS_SUBSCRIPT_IMPL_(BOOST_PP_EMPTY, BOOST_PROTO_CONST)                      \
 
370
        /**/
 
371
 
 
372
    #define BOOST_PROTO_EXTENDS_SUBSCRIPT()                                                         \
 
373
        BOOST_PROTO_EXTENDS_SUBSCRIPT_CONST()                                                       \
 
374
        BOOST_PROTO_EXTENDS_SUBSCRIPT_NON_CONST()                                                   \
 
375
        /**/
 
376
 
 
377
        /// INTERNAL ONLY
 
378
        ///
 
379
    #define BOOST_PROTO_EXTENDS_FUNCTION_()                                                         \
 
380
        template<typename Sig>                                                                      \
 
381
        struct result                                                                               \
 
382
        {                                                                                           \
 
383
            typedef                                                                                 \
 
384
                typename BOOST_PROTO_RESULT_OF<                                                     \
 
385
                    proto_generator(                                                                \
 
386
                        typename boost::proto::result_of::funop<                                    \
 
387
                            Sig                                                                     \
 
388
                          , proto_derived_expr                                                      \
 
389
                          , proto_domain                                                            \
 
390
                        >::type                                                                     \
 
391
                    )                                                                               \
 
392
                >::type const                                                                       \
 
393
            type;                                                                                   \
 
394
        };                                                                                          \
 
395
        /**/
 
396
 
 
397
    #ifndef BOOST_NO_VARIADIC_TEMPLATES
 
398
        #define BOOST_PROTO_EXTENDS_FUNCTION_CONST()                                                \
 
399
            BOOST_PROTO_EXTENDS_FUNCTION_()                                                         \
 
400
            BOOST_PROTO_DEFINE_FUN_OP_VARIADIC_IMPL_(BOOST_PROTO_CONST)                             \
 
401
            /**/
 
402
 
 
403
        #define BOOST_PROTO_EXTENDS_FUNCTION_NON_CONST()                                            \
 
404
            BOOST_PROTO_EXTENDS_FUNCTION_()                                                         \
 
405
            BOOST_PROTO_DEFINE_FUN_OP_VARIADIC_IMPL_(BOOST_PP_EMPTY)                                \
 
406
            /**/
 
407
 
 
408
        #define BOOST_PROTO_EXTENDS_FUNCTION()                                                      \
 
409
            BOOST_PROTO_EXTENDS_FUNCTION_()                                                         \
 
410
            BOOST_PROTO_DEFINE_FUN_OP_VARIADIC_IMPL_(BOOST_PP_EMPTY)                                \
 
411
            BOOST_PROTO_DEFINE_FUN_OP_VARIADIC_IMPL_(BOOST_PROTO_CONST)                             \
 
412
            /**/
 
413
    #else
 
414
        #define BOOST_PROTO_EXTENDS_FUNCTION_CONST()                                                \
 
415
            BOOST_PROTO_EXTENDS_FUNCTION_()                                                         \
 
416
            BOOST_PP_REPEAT_FROM_TO(                                                                \
 
417
                0                                                                                   \
 
418
              , BOOST_PROTO_MAX_FUNCTION_CALL_ARITY                                                 \
 
419
              , BOOST_PROTO_DEFINE_FUN_OP_CONST                                                     \
 
420
              , ~                                                                                   \
 
421
            )                                                                                       \
 
422
            /**/
 
423
 
 
424
        #define BOOST_PROTO_EXTENDS_FUNCTION_NON_CONST()                                            \
 
425
            BOOST_PROTO_EXTENDS_FUNCTION_()                                                         \
 
426
            BOOST_PP_REPEAT_FROM_TO(                                                                \
 
427
                0                                                                                   \
 
428
              , BOOST_PROTO_MAX_FUNCTION_CALL_ARITY                                                 \
 
429
              , BOOST_PROTO_DEFINE_FUN_OP_NON_CONST                                                 \
 
430
              , ~                                                                                   \
 
431
            )                                                                                       \
 
432
            /**/
 
433
 
 
434
        #define BOOST_PROTO_EXTENDS_FUNCTION()                                                      \
 
435
            BOOST_PROTO_EXTENDS_FUNCTION_()                                                         \
 
436
            BOOST_PP_REPEAT_FROM_TO(                                                                \
 
437
                0                                                                                   \
 
438
              , BOOST_PROTO_MAX_FUNCTION_CALL_ARITY                                                 \
 
439
              , BOOST_PROTO_DEFINE_FUN_OP                                                           \
 
440
              , ~                                                                                   \
 
441
            )                                                                                       \
 
442
            /**/
 
443
    #endif
 
444
 
 
445
    #define BOOST_PROTO_EXTENDS(Expr, Derived, Domain)                                              \
 
446
        BOOST_PROTO_BASIC_EXTENDS(Expr, Derived, Domain)                                            \
 
447
        BOOST_PROTO_EXTENDS_ASSIGN()                                                                \
 
448
        BOOST_PROTO_EXTENDS_SUBSCRIPT()                                                             \
 
449
        BOOST_PROTO_EXTENDS_FUNCTION()                                                              \
 
450
        /**/
 
451
 
 
452
    #define BOOST_PROTO_EXTENDS_USING_ASSIGN(Derived)                                               \
 
453
        typedef typename Derived::proto_extends proto_extends;                                      \
 
454
        using proto_extends::operator =;                                                            \
 
455
        BOOST_PROTO_EXTENDS_COPY_ASSIGN_(Derived, BOOST_PROTO_TYPENAME)                             \
 
456
        /**/
 
457
 
 
458
    #define BOOST_PROTO_EXTENDS_USING_ASSIGN_NON_DEPENDENT(Derived)                                 \
 
459
        typedef Derived::proto_extends proto_extends;                                               \
 
460
        using proto_extends::operator =;                                                            \
 
461
        BOOST_PROTO_EXTENDS_COPY_ASSIGN_(Derived, BOOST_PP_EMPTY)                                   \
 
462
        /**/
 
463
 
 
464
    namespace exprns_
 
465
    {
 
466
        /// \brief Empty type to be used as a dummy template parameter of
 
467
        ///     POD expression wrappers. It allows argument-dependent lookup
 
468
        ///     to find Proto's operator overloads.
 
469
        ///
 
470
        /// \c proto::is_proto_expr allows argument-dependent lookup
 
471
        ///     to find Proto's operator overloads. For example:
 
472
        ///
 
473
        /// \code
 
474
        /// template<typename T, typename Dummy = proto::is_proto_expr>
 
475
        /// struct my_terminal
 
476
        /// {
 
477
        ///     BOOST_PROTO_BASIC_EXTENDS(
 
478
        ///         typename proto::terminal<T>::type
 
479
        ///       , my_terminal<T>
 
480
        ///       , default_domain
 
481
        ///     )
 
482
        /// };
 
483
        ///
 
484
        /// // ...
 
485
        /// my_terminal<int> _1, _2;
 
486
        /// _1 + _2; // OK, uses proto::operator+
 
487
        /// \endcode
 
488
        ///
 
489
        /// Without the second \c Dummy template parameter, Proto's operator
 
490
        /// overloads would not be considered by name lookup.
 
491
        struct is_proto_expr
 
492
        {};
 
493
 
 
494
        /// \brief extends\<\> class template for adding behaviors to a Proto expression template
 
495
        ///
 
496
        template<
 
497
            typename Expr
 
498
          , typename Derived
 
499
          , typename Domain     // = proto::default_domain
 
500
          , long Arity          // = Expr::proto_arity_c
 
501
        >
 
502
        struct extends
 
503
        {
 
504
            BOOST_FORCEINLINE
 
505
            extends()
 
506
              : proto_expr_()
 
507
            {}
 
508
 
 
509
            BOOST_FORCEINLINE
 
510
            extends(extends const &that)
 
511
              : proto_expr_(that.proto_expr_)
 
512
            {}
 
513
 
 
514
            BOOST_FORCEINLINE
 
515
            extends(Expr const &expr_)
 
516
              : proto_expr_(expr_)
 
517
            {}
 
518
 
 
519
            typedef extends proto_extends;
 
520
            BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, typename Domain)
 
521
            BOOST_PROTO_EXTENDS_ASSIGN_CONST_()
 
522
            BOOST_PROTO_EXTENDS_SUBSCRIPT_CONST()
 
523
 
 
524
            // Instead of using BOOST_PROTO_EXTENDS_FUNCTION, which uses
 
525
            // nested preprocessor loops, use file iteration here to generate
 
526
            // the operator() overloads, which is more efficient.
 
527
            #include <boost/proto/detail/extends_funop_const.hpp>
 
528
        };
 
529
 
 
530
        /// \brief extends\<\> class template for adding behaviors to a Proto expression template
 
531
        ///
 
532
        template<typename Expr, typename Derived, typename Domain>
 
533
        struct extends<Expr, Derived, Domain, 0>
 
534
        {
 
535
            BOOST_FORCEINLINE
 
536
            extends()
 
537
              : proto_expr_()
 
538
            {}
 
539
 
 
540
            BOOST_FORCEINLINE
 
541
            extends(extends const &that)
 
542
              : proto_expr_(that.proto_expr_)
 
543
            {}
 
544
 
 
545
            BOOST_FORCEINLINE
 
546
            extends(Expr const &expr_)
 
547
              : proto_expr_(expr_)
 
548
            {}
 
549
 
 
550
            typedef extends proto_extends;
 
551
            BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, typename Domain)
 
552
            BOOST_PROTO_EXTENDS_ASSIGN_()
 
553
            BOOST_PROTO_EXTENDS_SUBSCRIPT()
 
554
 
 
555
            // Instead of using BOOST_PROTO_EXTENDS_FUNCTION, which uses
 
556
            // nested preprocessor loops, use file iteration here to generate
 
557
            // the operator() overloads, which is more efficient.
 
558
            #include <boost/proto/detail/extends_funop.hpp>
 
559
        };
 
560
 
 
561
        /// INTERNAL ONLY
 
562
        ///
 
563
        template<typename This, typename Fun, typename Domain>
 
564
        struct virtual_member
 
565
        {
 
566
            typedef Domain proto_domain;
 
567
            typedef typename Domain::proto_generator proto_generator;
 
568
            typedef virtual_member<This, Fun, Domain> proto_derived_expr;
 
569
            typedef tag::member proto_tag;
 
570
            typedef list2<This &, expr<tag::terminal, term<Fun> > const &> proto_args;
 
571
            typedef mpl::long_<2> proto_arity;
 
572
            typedef detail::not_a_valid_type proto_address_of_hack_type_;
 
573
            typedef void proto_is_expr_; /**< INTERNAL ONLY */
 
574
            static const long proto_arity_c = 2;
 
575
            typedef boost::proto::tag::proto_expr fusion_tag;
 
576
            typedef This &proto_child0;
 
577
            typedef expr<tag::terminal, term<Fun> > const &proto_child1;
 
578
            typedef expr<proto_tag, proto_args, proto_arity_c> proto_base_expr;
 
579
            typedef basic_expr<proto_tag, proto_args, proto_arity_c> proto_grammar;
 
580
            typedef void proto_is_aggregate_; /**< INTERNAL ONLY */
 
581
 
 
582
            BOOST_PROTO_EXTENDS_ASSIGN_()
 
583
            BOOST_PROTO_EXTENDS_SUBSCRIPT()
 
584
 
 
585
            // Instead of using BOOST_PROTO_EXTENDS_FUNCTION, which uses
 
586
            // nested preprocessor loops, use file iteration here to generate
 
587
            // the operator() overloads, which is more efficient.
 
588
            #define BOOST_PROTO_NO_WAVE_OUTPUT
 
589
            #include <boost/proto/detail/extends_funop.hpp>
 
590
            #undef BOOST_PROTO_NO_WAVE_OUTPUT
 
591
 
 
592
            BOOST_FORCEINLINE
 
593
            proto_base_expr const proto_base() const
 
594
            {
 
595
                proto_base_expr that = {this->child0(), this->child1()};
 
596
                return that;
 
597
            }
 
598
 
 
599
            BOOST_FORCEINLINE
 
600
            proto_child0 child0() const
 
601
            {
 
602
                using std::size_t;
 
603
                return *(This *)((char *)this - BOOST_PROTO_OFFSETOF(This, proto_member_union_start_));
 
604
            }
 
605
 
 
606
            BOOST_FORCEINLINE
 
607
            proto_child1 child1() const
 
608
            {
 
609
                static expr<tag::terminal, term<Fun>, 0> const that = {Fun()};
 
610
                return that;
 
611
            }
 
612
        };
 
613
 
 
614
        /// INTERNAL ONLY
 
615
        ///
 
616
        #define BOOST_PROTO_EXTENDS_MEMBER_(R, DOMAIN, ELEM)                                            \
 
617
            boost::proto::exprns_::virtual_member<                                                      \
 
618
                proto_derived_expr                                                                      \
 
619
              , BOOST_PP_TUPLE_ELEM(2, 0, ELEM)                                                         \
 
620
              , DOMAIN                                                                                  \
 
621
            > BOOST_PP_TUPLE_ELEM(2, 1, ELEM);                                                          \
 
622
            /**/
 
623
 
 
624
        /// \brief For declaring virtual data members in an extension class.
 
625
        ///
 
626
        #define BOOST_PROTO_EXTENDS_MEMBERS_WITH_DOMAIN(SEQ, DOMAIN)                                    \
 
627
            union                                                                                       \
 
628
            {                                                                                           \
 
629
                char proto_member_union_start_;                                                         \
 
630
                BOOST_PP_SEQ_FOR_EACH(BOOST_PROTO_EXTENDS_MEMBER_, DOMAIN, SEQ)                         \
 
631
            };                                                                                          \
 
632
            /**/
 
633
 
 
634
        /// \brief For declaring virtual data members in an extension class.
 
635
        ///
 
636
        #define BOOST_PROTO_EXTENDS_MEMBERS(SEQ)                                                        \
 
637
            BOOST_PROTO_EXTENDS_MEMBERS_WITH_DOMAIN(SEQ, proto_domain)                                  \
 
638
            /**/
 
639
 
 
640
    }
 
641
 
 
642
}}
 
643
 
 
644
#endif