Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:58:27

0001 ///////////////////////////////////////////////////////////////////////////////
0002 /// \file extends.hpp
0003 /// Macros and a base class for defining end-user expression types
0004 //
0005 //  Copyright 2008 Eric Niebler. Distributed under the Boost
0006 //  Software License, Version 1.0. (See accompanying file
0007 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 #ifndef BOOST_PROTO_EXTENDS_HPP_EAN_11_1_2006
0010 #define BOOST_PROTO_EXTENDS_HPP_EAN_11_1_2006
0011 
0012 #include <cstddef> // for offsetof
0013 #include <boost/config.hpp>
0014 #include <boost/detail/workaround.hpp>
0015 #include <boost/preprocessor/facilities/empty.hpp>
0016 #include <boost/preprocessor/tuple/elem.hpp>
0017 #include <boost/preprocessor/control/if.hpp>
0018 #include <boost/preprocessor/arithmetic/inc.hpp>
0019 #include <boost/preprocessor/arithmetic/dec.hpp>
0020 #include <boost/preprocessor/iteration/local.hpp>
0021 #include <boost/preprocessor/repetition/enum_params.hpp>
0022 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
0023 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
0024 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
0025 #include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
0026 #include <boost/preprocessor/seq/for_each.hpp>
0027 #include <boost/utility/addressof.hpp>
0028 #include <boost/utility/result_of.hpp>
0029 #include <boost/proto/proto_fwd.hpp>
0030 #include <boost/proto/traits.hpp>
0031 #include <boost/proto/expr.hpp>
0032 #include <boost/proto/args.hpp>
0033 #include <boost/proto/traits.hpp>
0034 #include <boost/proto/generate.hpp>
0035 #include <boost/proto/detail/remove_typename.hpp>
0036 
0037 #if defined(_MSC_VER)
0038 # pragma warning(push)
0039 # pragma warning(disable : 4714) // function 'xxx' marked as __forceinline not inlined
0040 #endif
0041 
0042 namespace boost { namespace proto
0043 {
0044     #ifdef __GNUC__
0045     /// INTERNAL ONLY
0046     ///
0047     # define BOOST_PROTO_ADDROF(x) ((char const volatile*)boost::addressof(x))
0048     /// INTERNAL ONLY
0049     ///
0050     # define BOOST_PROTO_OFFSETOF(s,m) (BOOST_PROTO_ADDROF((((s *)this)->m)) - BOOST_PROTO_ADDROF(*((s *)this)))
0051     #else
0052     /// INTERNAL ONLY
0053     ///
0054     # define BOOST_PROTO_OFFSETOF offsetof
0055     #endif
0056 
0057     /// INTERNAL ONLY
0058     ///
0059     #define BOOST_PROTO_CONST() const
0060 
0061     /// INTERNAL ONLY
0062     ///
0063     #define BOOST_PROTO_TYPENAME() typename
0064 
0065     /// INTERNAL ONLY
0066     ///
0067     #define BOOST_PROTO_TEMPLATE_YES_(Z, N) template<BOOST_PP_ENUM_PARAMS_Z(Z, N, typename A)>
0068 
0069     /// INTERNAL ONLY
0070     ///
0071     #define BOOST_PROTO_TEMPLATE_NO_(Z, N)
0072 
0073     /// INTERNAL ONLY
0074     ///
0075     #define BOOST_PROTO_DEFINE_FUN_OP_IMPL_(Z, N, DATA, Const)                                      \
0076         BOOST_PP_IF(N, BOOST_PROTO_TEMPLATE_YES_, BOOST_PROTO_TEMPLATE_NO_)(Z, N)                   \
0077         BOOST_PROTO_PUSH_WARNINGS                                                                   \
0078         BOOST_PROTO_DISABLE_MSVC_C4180                                                              \
0079         BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE                                            \
0080         typename BOOST_PROTO_RESULT_OF<                                                             \
0081             proto_generator(                                                                        \
0082                 typename boost::proto::result_of::BOOST_PP_CAT(funop, N)<                           \
0083                     proto_derived_expr Const()                                                      \
0084                   , proto_domain                                                                    \
0085                     BOOST_PP_ENUM_TRAILING_PARAMS_Z(Z, N, const A)                                  \
0086                 >::type                                                                             \
0087             )                                                                                       \
0088         >::type const                                                                               \
0089         operator ()(BOOST_PP_ENUM_BINARY_PARAMS_Z(Z, N, A, const &a)) Const()                       \
0090         {                                                                                           \
0091             typedef boost::proto::result_of::BOOST_PP_CAT(funop, N)<                                \
0092                 proto_derived_expr Const()                                                          \
0093               , proto_domain                                                                        \
0094                 BOOST_PP_ENUM_TRAILING_PARAMS_Z(Z, N, const A)                                      \
0095             > funop;                                                                                \
0096             return proto_generator()(                                                               \
0097                 funop::call(                                                                        \
0098                     *static_cast<proto_derived_expr Const() *>(this)                                \
0099                     BOOST_PP_ENUM_TRAILING_PARAMS_Z(Z, N, a)                                        \
0100                 )                                                                                   \
0101             );                                                                                      \
0102         }                                                                                           \
0103         BOOST_PROTO_POP_WARNINGS                                                                    \
0104         /**/
0105 
0106     /// INTERNAL ONLY
0107     ///
0108     #define BOOST_PROTO_DEFINE_FUN_OP_VARIADIC_IMPL_(Const)                                         \
0109         template<typename... A>                                                                     \
0110         BOOST_PROTO_PUSH_WARNINGS                                                                   \
0111         BOOST_PROTO_DISABLE_MSVC_C4180                                                              \
0112         BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE                                            \
0113         typename BOOST_PROTO_RESULT_OF<                                                             \
0114             proto_generator(                                                                        \
0115                 typename boost::proto::result_of::funop<                                            \
0116                     proto_derived_expr Const()(A const &...)                                        \
0117                   , proto_derived_expr                                                              \
0118                   , proto_domain                                                                    \
0119                 >::type                                                                             \
0120             )                                                                                       \
0121         >::type const                                                                               \
0122         operator ()(A const &...a) Const()                                                          \
0123         {                                                                                           \
0124             typedef boost::proto::result_of::funop<                                                 \
0125                 proto_derived_expr Const()(A const &...)                                            \
0126               , proto_derived_expr                                                                  \
0127               , proto_domain                                                                        \
0128             > funop;                                                                                \
0129             return proto_generator()(                                                               \
0130                 funop::call(                                                                        \
0131                     *static_cast<proto_derived_expr Const() *>(this)                                \
0132                   , a...                                                                            \
0133                 )                                                                                   \
0134             );                                                                                      \
0135         }                                                                                           \
0136         BOOST_PROTO_POP_WARNINGS                                                                    \
0137         /**/
0138 
0139     /// INTERNAL ONLY
0140     ///
0141     #define BOOST_PROTO_DEFINE_FUN_OP_CONST(Z, N, DATA)                                             \
0142         BOOST_PROTO_DEFINE_FUN_OP_IMPL_(Z, N, DATA, BOOST_PROTO_CONST)                              \
0143         /**/
0144 
0145     /// INTERNAL ONLY
0146     ///
0147     #define BOOST_PROTO_DEFINE_FUN_OP_NON_CONST(Z, N, DATA)                                         \
0148         BOOST_PROTO_DEFINE_FUN_OP_IMPL_(Z, N, DATA, BOOST_PP_EMPTY)                                 \
0149         /**/
0150 
0151     /// INTERNAL ONLY
0152     ///
0153     #define BOOST_PROTO_DEFINE_FUN_OP(Z, N, DATA)                                                   \
0154         BOOST_PROTO_DEFINE_FUN_OP_CONST(Z, N, DATA)                                                 \
0155         BOOST_PROTO_DEFINE_FUN_OP_NON_CONST(Z, N, DATA)                                             \
0156         /**/
0157 
0158     /// INTERNAL ONLY
0159     ///
0160     #define BOOST_PROTO_EXTENDS_CHILD(Z, N, DATA)                                                   \
0161         typedef                                                                                     \
0162             typename proto_base_expr::BOOST_PP_CAT(proto_child, N)                                  \
0163         BOOST_PP_CAT(proto_child, N);                                                               \
0164         /**/
0165 
0166     #define BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, Domain)                                       \
0167         Expr proto_expr_;                                                                           \
0168                                                                                                     \
0169         typedef Expr proto_base_expr_; /**< INTERNAL ONLY */                                        \
0170         typedef typename proto_base_expr_::proto_base_expr proto_base_expr;                         \
0171         typedef BOOST_PROTO_REMOVE_TYPENAME(Domain) proto_domain;                                   \
0172         typedef Derived proto_derived_expr;                                                         \
0173         typedef Domain::proto_generator proto_generator;                                            \
0174         typedef typename proto_base_expr::proto_tag proto_tag;                                      \
0175         typedef typename proto_base_expr::proto_args proto_args;                                    \
0176         typedef typename proto_base_expr::proto_arity proto_arity;                                  \
0177         typedef typename proto_base_expr::proto_grammar proto_grammar;                              \
0178         typedef typename proto_base_expr::address_of_hack_type_ proto_address_of_hack_type_;        \
0179         typedef void proto_is_expr_; /**< INTERNAL ONLY */                                          \
0180         static const long proto_arity_c = proto_base_expr::proto_arity_c;                           \
0181         typedef boost::proto::tag::proto_expr<proto_tag, proto_domain> fusion_tag;                  \
0182         BOOST_PP_REPEAT(BOOST_PROTO_MAX_ARITY, BOOST_PROTO_EXTENDS_CHILD, ~)                        \
0183                                                                                                     \
0184         BOOST_PROTO_PUSH_WARNINGS                                                                   \
0185                                                                                                     \
0186         BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE                                            \
0187         static proto_derived_expr const make(Expr const &e)                                         \
0188         {                                                                                           \
0189             proto_derived_expr that = {e};                                                          \
0190             return that;                                                                            \
0191         }                                                                                           \
0192                                                                                                     \
0193         BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE                                            \
0194         proto_base_expr &proto_base()                                                               \
0195         {                                                                                           \
0196             return this->proto_expr_.proto_base();                                                  \
0197         }                                                                                           \
0198                                                                                                     \
0199         BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE                                            \
0200         proto_base_expr const &proto_base() const                                                   \
0201         {                                                                                           \
0202             return this->proto_expr_.proto_base();                                                  \
0203         }                                                                                           \
0204                                                                                                     \
0205         BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE                                            \
0206         operator proto_address_of_hack_type_() const                                                \
0207         {                                                                                           \
0208             return boost::addressof(this->proto_base().child0);                                     \
0209         }                                                                                           \
0210                                                                                                     \
0211         BOOST_PROTO_POP_WARNINGS                                                                    \
0212         /**/
0213 
0214     #define BOOST_PROTO_BASIC_EXTENDS(Expr, Derived, Domain)                                        \
0215         BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, Domain)                                           \
0216         typedef void proto_is_aggregate_;                                                           \
0217         /**< INTERNAL ONLY */
0218 
0219     #define BOOST_PROTO_EXTENDS_COPY_ASSIGN_IMPL_(This, Const, Typename)                            \
0220         BOOST_PROTO_PUSH_WARNINGS                                                                   \
0221         BOOST_PROTO_DISABLE_MSVC_C4522                                                              \
0222         BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE                                            \
0223         Typename() BOOST_PROTO_RESULT_OF<                                                           \
0224             Typename() This::proto_generator(                                                       \
0225                 Typename() boost::proto::base_expr<                                                 \
0226                     Typename() This::proto_domain                                                   \
0227                   , boost::proto::tag::assign                                                       \
0228                   , boost::proto::list2<                                                            \
0229                         This &                                                                      \
0230                       , This Const() &                                                              \
0231                     >                                                                               \
0232                 >::type                                                                             \
0233             )                                                                                       \
0234         >::type const                                                                               \
0235         operator =(This Const() &a)                                                                 \
0236         {                                                                                           \
0237             typedef                                                                                 \
0238                 Typename() boost::proto::base_expr<                                                 \
0239                     Typename() This::proto_domain                                                   \
0240                   , boost::proto::tag::assign                                                       \
0241                   , boost::proto::list2<                                                            \
0242                         This &                                                                      \
0243                       , This Const() &                                                              \
0244                     >                                                                               \
0245                 >::type                                                                             \
0246             that_type;                                                                              \
0247             that_type const that = {                                                                \
0248                 *this                                                                               \
0249               , a                                                                                   \
0250             };                                                                                      \
0251             return Typename() This::proto_generator()(that);                                        \
0252         }                                                                                           \
0253         BOOST_PROTO_POP_WARNINGS                                                                    \
0254         /**/
0255 
0256         // MSVC 8.0 and higher seem to need copy-assignment operator to be overloaded on *both*
0257         // const and non-const rhs arguments.
0258     #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600)) && (BOOST_MSVC > 1310)
0259         #define BOOST_PROTO_EXTENDS_COPY_ASSIGN_(This, Typename)                                    \
0260             BOOST_PROTO_EXTENDS_COPY_ASSIGN_IMPL_(This, BOOST_PP_EMPTY, Typename)                   \
0261             BOOST_PROTO_EXTENDS_COPY_ASSIGN_IMPL_(This, BOOST_PROTO_CONST, Typename)                \
0262             /**/
0263     #else
0264         #define BOOST_PROTO_EXTENDS_COPY_ASSIGN_(This, Typename)                                    \
0265             BOOST_PROTO_EXTENDS_COPY_ASSIGN_IMPL_(This, BOOST_PROTO_CONST, Typename)                \
0266             /**/
0267     #endif
0268 
0269         /// INTERNAL ONLY
0270         ///
0271     #define BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(ThisConst, ThatConst)                                  \
0272         template<typename A>                                                                        \
0273         BOOST_PROTO_PUSH_WARNINGS                                                                   \
0274         BOOST_PROTO_DISABLE_MSVC_C4180                                                              \
0275         BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE                                            \
0276         typename BOOST_PROTO_RESULT_OF<                                                             \
0277             proto_generator(                                                                        \
0278                 typename boost::proto::base_expr<                                                   \
0279                     proto_domain                                                                    \
0280                   , boost::proto::tag::assign                                                       \
0281                   , boost::proto::list2<                                                            \
0282                         proto_derived_expr ThisConst() &                                            \
0283                       , typename boost::proto::result_of::as_child<A ThatConst(), proto_domain>::type \
0284                     >                                                                               \
0285                 >::type                                                                             \
0286             )                                                                                       \
0287         >::type const                                                                               \
0288         operator =(A ThatConst() &a) ThisConst()                                                    \
0289         {                                                                                           \
0290             typedef                                                                                 \
0291                 typename boost::proto::base_expr<                                                   \
0292                     proto_domain                                                                    \
0293                   , boost::proto::tag::assign                                                       \
0294                   , boost::proto::list2<                                                            \
0295                         proto_derived_expr ThisConst() &                                            \
0296                       , typename boost::proto::result_of::as_child<A ThatConst(), proto_domain>::type \
0297                     >                                                                               \
0298                 >::type                                                                             \
0299             that_type;                                                                              \
0300             that_type const that = {                                                                \
0301                 *static_cast<proto_derived_expr ThisConst() *>(this)                                \
0302               , boost::proto::as_child<proto_domain>(a)                                             \
0303             };                                                                                      \
0304             return proto_generator()(that);                                                         \
0305         }                                                                                           \
0306         BOOST_PROTO_POP_WARNINGS                                                                    \
0307         /**/
0308 
0309     #define BOOST_PROTO_EXTENDS_ASSIGN_CONST_()                                                     \
0310         BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(BOOST_PROTO_CONST, BOOST_PP_EMPTY)                         \
0311         BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(BOOST_PROTO_CONST, BOOST_PROTO_CONST)                      \
0312         /**/
0313 
0314     #define BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST_()                                                 \
0315         BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(BOOST_PP_EMPTY, BOOST_PP_EMPTY)                            \
0316         BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(BOOST_PP_EMPTY, BOOST_PROTO_CONST)                         \
0317         /**/
0318 
0319     #define BOOST_PROTO_EXTENDS_ASSIGN_()                                                           \
0320         BOOST_PROTO_EXTENDS_ASSIGN_CONST_()                                                         \
0321         BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST_()                                                     \
0322         /**/
0323 
0324     #define BOOST_PROTO_EXTENDS_ASSIGN_CONST()                                                      \
0325         BOOST_PROTO_EXTENDS_COPY_ASSIGN_(proto_derived_expr, BOOST_PROTO_TYPENAME)                  \
0326         BOOST_PROTO_EXTENDS_ASSIGN_CONST_()                                                         \
0327         /**/
0328 
0329     #define BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST()                                                  \
0330         BOOST_PROTO_EXTENDS_COPY_ASSIGN_(proto_derived_expr, BOOST_PROTO_TYPENAME)                  \
0331         BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST_()                                                     \
0332         /**/
0333 
0334     #define BOOST_PROTO_EXTENDS_ASSIGN()                                                            \
0335         BOOST_PROTO_EXTENDS_COPY_ASSIGN_(proto_derived_expr, BOOST_PROTO_TYPENAME)                  \
0336         BOOST_PROTO_EXTENDS_ASSIGN_()                                                               \
0337         /**/
0338 
0339         /// INTERNAL ONLY
0340         ///
0341     #define BOOST_PROTO_EXTENDS_SUBSCRIPT_IMPL_(ThisConst, ThatConst)                               \
0342         template<typename A>                                                                        \
0343         BOOST_PROTO_PUSH_WARNINGS                                                                   \
0344         BOOST_PROTO_DISABLE_MSVC_C4180                                                              \
0345         BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE                                            \
0346         typename BOOST_PROTO_RESULT_OF<                                                             \
0347             proto_generator(                                                                        \
0348                 typename boost::proto::base_expr<                                                   \
0349                     proto_domain                                                                    \
0350                   , boost::proto::tag::subscript                                                    \
0351                   , boost::proto::list2<                                                            \
0352                         proto_derived_expr ThisConst() &                                            \
0353                       , typename boost::proto::result_of::as_child<A ThatConst(), proto_domain>::type \
0354                     >                                                                               \
0355                 >::type                                                                             \
0356             )                                                                                       \
0357         >::type const                                                                               \
0358         operator [](A ThatConst() &a) ThisConst()                                                   \
0359         {                                                                                           \
0360             typedef                                                                                 \
0361                 typename boost::proto::base_expr<                                                   \
0362                     proto_domain                                                                    \
0363                   , boost::proto::tag::subscript                                                    \
0364                   , boost::proto::list2<                                                            \
0365                         proto_derived_expr ThisConst() &                                            \
0366                       , typename boost::proto::result_of::as_child<A ThatConst(), proto_domain>::type \
0367                     >                                                                               \
0368                 >::type                                                                             \
0369             that_type;                                                                              \
0370             that_type const that = {                                                                \
0371                 *static_cast<proto_derived_expr ThisConst() *>(this)                                \
0372               , boost::proto::as_child<proto_domain>(a)                                             \
0373             };                                                                                      \
0374             return proto_generator()(that);                                                         \
0375         }                                                                                           \
0376         BOOST_PROTO_POP_WARNINGS                                                                    \
0377         /**/
0378 
0379     #define BOOST_PROTO_EXTENDS_SUBSCRIPT_CONST()                                                   \
0380         BOOST_PROTO_EXTENDS_SUBSCRIPT_IMPL_(BOOST_PROTO_CONST, BOOST_PP_EMPTY)                      \
0381         BOOST_PROTO_EXTENDS_SUBSCRIPT_IMPL_(BOOST_PROTO_CONST, BOOST_PROTO_CONST)                   \
0382         /**/
0383 
0384     #define BOOST_PROTO_EXTENDS_SUBSCRIPT_NON_CONST()                                               \
0385         BOOST_PROTO_EXTENDS_SUBSCRIPT_IMPL_(BOOST_PP_EMPTY, BOOST_PP_EMPTY)                         \
0386         BOOST_PROTO_EXTENDS_SUBSCRIPT_IMPL_(BOOST_PP_EMPTY, BOOST_PROTO_CONST)                      \
0387         /**/
0388 
0389     #define BOOST_PROTO_EXTENDS_SUBSCRIPT()                                                         \
0390         BOOST_PROTO_EXTENDS_SUBSCRIPT_CONST()                                                       \
0391         BOOST_PROTO_EXTENDS_SUBSCRIPT_NON_CONST()                                                   \
0392         /**/
0393 
0394         /// INTERNAL ONLY
0395         ///
0396     #define BOOST_PROTO_EXTENDS_FUNCTION_()                                                         \
0397         template<typename Sig>                                                                      \
0398         struct result                                                                               \
0399         {                                                                                           \
0400             typedef                                                                                 \
0401                 typename BOOST_PROTO_RESULT_OF<                                                     \
0402                     proto_generator(                                                                \
0403                         typename boost::proto::result_of::funop<                                    \
0404                             Sig                                                                     \
0405                           , proto_derived_expr                                                      \
0406                           , proto_domain                                                            \
0407                         >::type                                                                     \
0408                     )                                                                               \
0409                 >::type const                                                                       \
0410             type;                                                                                   \
0411         };                                                                                          \
0412         /**/
0413 
0414     #ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
0415         #define BOOST_PROTO_EXTENDS_FUNCTION_CONST()                                                \
0416             BOOST_PROTO_EXTENDS_FUNCTION_()                                                         \
0417             BOOST_PROTO_DEFINE_FUN_OP_VARIADIC_IMPL_(BOOST_PROTO_CONST)                             \
0418             /**/
0419 
0420         #define BOOST_PROTO_EXTENDS_FUNCTION_NON_CONST()                                            \
0421             BOOST_PROTO_EXTENDS_FUNCTION_()                                                         \
0422             BOOST_PROTO_DEFINE_FUN_OP_VARIADIC_IMPL_(BOOST_PP_EMPTY)                                \
0423             /**/
0424 
0425         #define BOOST_PROTO_EXTENDS_FUNCTION()                                                      \
0426             BOOST_PROTO_EXTENDS_FUNCTION_()                                                         \
0427             BOOST_PROTO_DEFINE_FUN_OP_VARIADIC_IMPL_(BOOST_PP_EMPTY)                                \
0428             BOOST_PROTO_DEFINE_FUN_OP_VARIADIC_IMPL_(BOOST_PROTO_CONST)                             \
0429             /**/
0430     #else
0431         #define BOOST_PROTO_EXTENDS_FUNCTION_CONST()                                                \
0432             BOOST_PROTO_EXTENDS_FUNCTION_()                                                         \
0433             BOOST_PP_REPEAT_FROM_TO(                                                                \
0434                 0                                                                                   \
0435               , BOOST_PROTO_MAX_FUNCTION_CALL_ARITY                                                 \
0436               , BOOST_PROTO_DEFINE_FUN_OP_CONST                                                     \
0437               , ~                                                                                   \
0438             )                                                                                       \
0439             /**/
0440 
0441         #define BOOST_PROTO_EXTENDS_FUNCTION_NON_CONST()                                            \
0442             BOOST_PROTO_EXTENDS_FUNCTION_()                                                         \
0443             BOOST_PP_REPEAT_FROM_TO(                                                                \
0444                 0                                                                                   \
0445               , BOOST_PROTO_MAX_FUNCTION_CALL_ARITY                                                 \
0446               , BOOST_PROTO_DEFINE_FUN_OP_NON_CONST                                                 \
0447               , ~                                                                                   \
0448             )                                                                                       \
0449             /**/
0450 
0451         #define BOOST_PROTO_EXTENDS_FUNCTION()                                                      \
0452             BOOST_PROTO_EXTENDS_FUNCTION_()                                                         \
0453             BOOST_PP_REPEAT_FROM_TO(                                                                \
0454                 0                                                                                   \
0455               , BOOST_PROTO_MAX_FUNCTION_CALL_ARITY                                                 \
0456               , BOOST_PROTO_DEFINE_FUN_OP                                                           \
0457               , ~                                                                                   \
0458             )                                                                                       \
0459             /**/
0460     #endif
0461 
0462     #define BOOST_PROTO_EXTENDS(Expr, Derived, Domain)                                              \
0463         BOOST_PROTO_BASIC_EXTENDS(Expr, Derived, Domain)                                            \
0464         BOOST_PROTO_EXTENDS_ASSIGN()                                                                \
0465         BOOST_PROTO_EXTENDS_SUBSCRIPT()                                                             \
0466         BOOST_PROTO_EXTENDS_FUNCTION()                                                              \
0467         /**/
0468 
0469     #define BOOST_PROTO_EXTENDS_USING_ASSIGN(Derived)                                               \
0470         typedef typename Derived::proto_extends proto_extends;                                      \
0471         using proto_extends::operator =;                                                            \
0472         BOOST_PROTO_EXTENDS_COPY_ASSIGN_(Derived, BOOST_PROTO_TYPENAME)                             \
0473         /**/
0474 
0475     #define BOOST_PROTO_EXTENDS_USING_ASSIGN_NON_DEPENDENT(Derived)                                 \
0476         typedef Derived::proto_extends proto_extends;                                               \
0477         using proto_extends::operator =;                                                            \
0478         BOOST_PROTO_EXTENDS_COPY_ASSIGN_(Derived, BOOST_PP_EMPTY)                                   \
0479         /**/
0480 
0481     namespace exprns_
0482     {
0483         /// \brief Empty type to be used as a dummy template parameter of
0484         ///     POD expression wrappers. It allows argument-dependent lookup
0485         ///     to find Proto's operator overloads.
0486         ///
0487         /// \c proto::is_proto_expr allows argument-dependent lookup
0488         ///     to find Proto's operator overloads. For example:
0489         ///
0490         /// \code
0491         /// template<typename T, typename Dummy = proto::is_proto_expr>
0492         /// struct my_terminal
0493         /// {
0494         ///     BOOST_PROTO_BASIC_EXTENDS(
0495         ///         typename proto::terminal<T>::type
0496         ///       , my_terminal<T>
0497         ///       , default_domain
0498         ///     )
0499         /// };
0500         ///
0501         /// // ...
0502         /// my_terminal<int> _1, _2;
0503         /// _1 + _2; // OK, uses proto::operator+
0504         /// \endcode
0505         ///
0506         /// Without the second \c Dummy template parameter, Proto's operator
0507         /// overloads would not be considered by name lookup.
0508         struct is_proto_expr
0509         {};
0510 
0511         /// \brief extends\<\> class template for adding behaviors to a Proto expression template
0512         ///
0513         template<
0514             typename Expr
0515           , typename Derived
0516           , typename Domain     // = proto::default_domain
0517           , long Arity          // = Expr::proto_arity_c
0518         >
0519         struct extends
0520         {
0521             BOOST_FORCEINLINE
0522             extends()
0523               : proto_expr_()
0524             {}
0525 
0526             BOOST_FORCEINLINE
0527             extends(Expr const &expr_)
0528               : proto_expr_(expr_)
0529             {}
0530 
0531             typedef extends proto_extends;
0532             BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, typename Domain)
0533             BOOST_PROTO_EXTENDS_ASSIGN_CONST_()
0534             BOOST_PROTO_EXTENDS_SUBSCRIPT_CONST()
0535 
0536             // Instead of using BOOST_PROTO_EXTENDS_FUNCTION, which uses
0537             // nested preprocessor loops, use file iteration here to generate
0538             // the operator() overloads, which is more efficient.
0539             #include <boost/proto/detail/extends_funop_const.hpp>
0540         };
0541 
0542         /// \brief extends\<\> class template for adding behaviors to a Proto expression template
0543         ///
0544         template<typename Expr, typename Derived, typename Domain>
0545         struct extends<Expr, Derived, Domain, 0>
0546         {
0547             BOOST_FORCEINLINE
0548             extends()
0549               : proto_expr_()
0550             {}
0551 
0552             BOOST_FORCEINLINE
0553             extends(Expr const &expr_)
0554               : proto_expr_(expr_)
0555             {}
0556 
0557             typedef extends proto_extends;
0558             BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, typename Domain)
0559             BOOST_PROTO_EXTENDS_ASSIGN_()
0560             BOOST_PROTO_EXTENDS_SUBSCRIPT()
0561 
0562             // Instead of using BOOST_PROTO_EXTENDS_FUNCTION, which uses
0563             // nested preprocessor loops, use file iteration here to generate
0564             // the operator() overloads, which is more efficient.
0565             #include <boost/proto/detail/extends_funop.hpp>
0566         };
0567 
0568         /// INTERNAL ONLY
0569         ///
0570         template<typename This, typename Fun, typename Domain>
0571         struct virtual_member
0572         {
0573             typedef Domain proto_domain;
0574             typedef typename Domain::proto_generator proto_generator;
0575             typedef virtual_member<This, Fun, Domain> proto_derived_expr;
0576             typedef tag::member proto_tag;
0577             typedef list2<This &, expr<tag::terminal, term<Fun> > const &> proto_args;
0578             typedef mpl::long_<2> proto_arity;
0579             typedef detail::not_a_valid_type proto_address_of_hack_type_;
0580             typedef void proto_is_expr_; /**< INTERNAL ONLY */
0581             static const long proto_arity_c = 2;
0582             typedef boost::proto::tag::proto_expr<proto_tag, Domain> fusion_tag;
0583             typedef This &proto_child0;
0584             typedef expr<tag::terminal, term<Fun> > const &proto_child1;
0585             typedef expr<proto_tag, proto_args, proto_arity_c> proto_base_expr;
0586             typedef basic_expr<proto_tag, proto_args, proto_arity_c> proto_grammar;
0587             typedef void proto_is_aggregate_; /**< INTERNAL ONLY */
0588 
0589             BOOST_PROTO_EXTENDS_ASSIGN_()
0590             BOOST_PROTO_EXTENDS_SUBSCRIPT()
0591 
0592             // Instead of using BOOST_PROTO_EXTENDS_FUNCTION, which uses
0593             // nested preprocessor loops, use file iteration here to generate
0594             // the operator() overloads, which is more efficient.
0595             #define BOOST_PROTO_NO_WAVE_OUTPUT
0596             #include <boost/proto/detail/extends_funop.hpp>
0597             #undef BOOST_PROTO_NO_WAVE_OUTPUT
0598 
0599             BOOST_FORCEINLINE
0600             proto_base_expr const proto_base() const
0601             {
0602                 proto_base_expr that = {this->child0(), this->child1()};
0603                 return that;
0604             }
0605 
0606             BOOST_FORCEINLINE
0607             proto_child0 child0() const
0608             {
0609                 using std::size_t;
0610                 return *(This *)((char *)this - BOOST_PROTO_OFFSETOF(This, proto_member_union_start_));
0611             }
0612 
0613             BOOST_FORCEINLINE
0614             proto_child1 child1() const
0615             {
0616                 static expr<tag::terminal, term<Fun>, 0> const that = {Fun()};
0617                 return that;
0618             }
0619         };
0620 
0621         /// INTERNAL ONLY
0622         ///
0623         #define BOOST_PROTO_EXTENDS_MEMBER_(R, DOMAIN, ELEM)                                            \
0624             boost::proto::exprns_::virtual_member<                                                      \
0625                 proto_derived_expr                                                                      \
0626               , BOOST_PP_TUPLE_ELEM(2, 0, ELEM)                                                         \
0627               , DOMAIN                                                                                  \
0628             > BOOST_PP_TUPLE_ELEM(2, 1, ELEM);                                                          \
0629             /**/
0630 
0631         /// \brief For declaring virtual data members in an extension class.
0632         ///
0633         #define BOOST_PROTO_EXTENDS_MEMBERS_WITH_DOMAIN(SEQ, DOMAIN)                                    \
0634             union                                                                                       \
0635             {                                                                                           \
0636                 char proto_member_union_start_;                                                         \
0637                 BOOST_PP_SEQ_FOR_EACH(BOOST_PROTO_EXTENDS_MEMBER_, DOMAIN, SEQ)                         \
0638             };                                                                                          \
0639             /**/
0640 
0641         /// \brief For declaring virtual data members in an extension class.
0642         ///
0643         #define BOOST_PROTO_EXTENDS_MEMBERS(SEQ)                                                        \
0644             BOOST_PROTO_EXTENDS_MEMBERS_WITH_DOMAIN(SEQ, proto_domain)                                  \
0645             /**/
0646 
0647     }
0648 
0649 }}
0650 
0651 #if defined(_MSC_VER)
0652 # pragma warning(pop)
0653 #endif
0654 
0655 #endif