Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: /// \file extends.hpp Chris@16: /// Macros and a base class for defining end-user expression types Chris@16: // Chris@16: // Copyright 2008 Eric Niebler. Distributed under the Boost Chris@16: // Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_PROTO_EXTENDS_HPP_EAN_11_1_2006 Chris@16: #define BOOST_PROTO_EXTENDS_HPP_EAN_11_1_2006 Chris@16: Chris@16: #include // for offsetof Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@101: #if defined(_MSC_VER) Chris@16: # pragma warning(push) Chris@16: # pragma warning(disable : 4714) // function 'xxx' marked as __forceinline not inlined Chris@16: #endif Chris@16: Chris@16: namespace boost { namespace proto Chris@16: { Chris@16: #ifdef __GNUC__ Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: # define BOOST_PROTO_ADDROF(x) ((char const volatile*)boost::addressof(x)) Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: # define BOOST_PROTO_OFFSETOF(s,m) (BOOST_PROTO_ADDROF((((s *)this)->m)) - BOOST_PROTO_ADDROF(*((s *)this))) Chris@16: #else Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: # define BOOST_PROTO_OFFSETOF offsetof Chris@16: #endif Chris@16: Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: #define BOOST_PROTO_CONST() const Chris@16: Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: #define BOOST_PROTO_TYPENAME() typename Chris@16: Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: #define BOOST_PROTO_TEMPLATE_YES_(Z, N) template Chris@16: Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: #define BOOST_PROTO_TEMPLATE_NO_(Z, N) Chris@16: Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: #define BOOST_PROTO_DEFINE_FUN_OP_IMPL_(Z, N, DATA, Const) \ Chris@16: BOOST_PP_IF(N, BOOST_PROTO_TEMPLATE_YES_, BOOST_PROTO_TEMPLATE_NO_)(Z, N) \ Chris@16: BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE \ Chris@16: typename BOOST_PROTO_RESULT_OF< \ Chris@16: proto_generator( \ Chris@16: typename boost::proto::result_of::BOOST_PP_CAT(funop, N)< \ Chris@16: proto_derived_expr Const() \ Chris@16: , proto_domain \ Chris@16: BOOST_PP_ENUM_TRAILING_PARAMS_Z(Z, N, const A) \ Chris@16: >::type \ Chris@16: ) \ Chris@16: >::type const \ Chris@16: operator ()(BOOST_PP_ENUM_BINARY_PARAMS_Z(Z, N, A, const &a)) Const() \ Chris@16: { \ Chris@16: typedef boost::proto::result_of::BOOST_PP_CAT(funop, N)< \ Chris@16: proto_derived_expr Const() \ Chris@16: , proto_domain \ Chris@16: BOOST_PP_ENUM_TRAILING_PARAMS_Z(Z, N, const A) \ Chris@16: > funop; \ Chris@16: return proto_generator()( \ Chris@16: funop::call( \ Chris@16: *static_cast(this) \ Chris@16: BOOST_PP_ENUM_TRAILING_PARAMS_Z(Z, N, a) \ Chris@16: ) \ Chris@16: ); \ Chris@16: } \ Chris@16: /**/ Chris@16: Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: #define BOOST_PROTO_DEFINE_FUN_OP_VARIADIC_IMPL_(Const) \ Chris@16: template \ Chris@16: BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE \ Chris@16: typename BOOST_PROTO_RESULT_OF< \ Chris@16: proto_generator( \ Chris@16: typename boost::proto::result_of::funop< \ Chris@16: proto_derived_expr Const()(A const &...) \ Chris@16: , proto_derived_expr \ Chris@16: , proto_domain \ Chris@16: >::type \ Chris@16: ) \ Chris@16: >::type const \ Chris@16: operator ()(A const &...a) Const() \ Chris@16: { \ Chris@16: typedef boost::proto::result_of::funop< \ Chris@16: proto_derived_expr Const()(A const &...) \ Chris@16: , proto_derived_expr \ Chris@16: , proto_domain \ Chris@16: > funop; \ Chris@16: return proto_generator()( \ Chris@16: funop::call( \ Chris@16: *static_cast(this) \ Chris@16: , a... \ Chris@16: ) \ Chris@16: ); \ Chris@16: } \ Chris@16: /**/ Chris@16: Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: #define BOOST_PROTO_DEFINE_FUN_OP_CONST(Z, N, DATA) \ Chris@16: BOOST_PROTO_DEFINE_FUN_OP_IMPL_(Z, N, DATA, BOOST_PROTO_CONST) \ Chris@16: /**/ Chris@16: Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: #define BOOST_PROTO_DEFINE_FUN_OP_NON_CONST(Z, N, DATA) \ Chris@16: BOOST_PROTO_DEFINE_FUN_OP_IMPL_(Z, N, DATA, BOOST_PP_EMPTY) \ Chris@16: /**/ Chris@16: Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: #define BOOST_PROTO_DEFINE_FUN_OP(Z, N, DATA) \ Chris@16: BOOST_PROTO_DEFINE_FUN_OP_CONST(Z, N, DATA) \ Chris@16: BOOST_PROTO_DEFINE_FUN_OP_NON_CONST(Z, N, DATA) \ Chris@16: /**/ Chris@16: Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: #define BOOST_PROTO_EXTENDS_CHILD(Z, N, DATA) \ Chris@16: typedef \ Chris@16: typename proto_base_expr::BOOST_PP_CAT(proto_child, N) \ Chris@16: BOOST_PP_CAT(proto_child, N); \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, Domain) \ Chris@16: Expr proto_expr_; \ Chris@16: \ Chris@16: typedef Expr proto_base_expr_; /**< INTERNAL ONLY */ \ Chris@16: typedef typename proto_base_expr_::proto_base_expr proto_base_expr; \ Chris@16: typedef BOOST_PROTO_REMOVE_TYPENAME(Domain) proto_domain; \ Chris@16: typedef Derived proto_derived_expr; \ Chris@16: typedef Domain::proto_generator proto_generator; \ Chris@16: typedef typename proto_base_expr::proto_tag proto_tag; \ Chris@16: typedef typename proto_base_expr::proto_args proto_args; \ Chris@16: typedef typename proto_base_expr::proto_arity proto_arity; \ Chris@16: typedef typename proto_base_expr::proto_grammar proto_grammar; \ Chris@16: typedef typename proto_base_expr::address_of_hack_type_ proto_address_of_hack_type_; \ Chris@16: typedef void proto_is_expr_; /**< INTERNAL ONLY */ \ Chris@16: static const long proto_arity_c = proto_base_expr::proto_arity_c; \ Chris@16: typedef boost::proto::tag::proto_expr fusion_tag; \ Chris@16: BOOST_PP_REPEAT(BOOST_PROTO_MAX_ARITY, BOOST_PROTO_EXTENDS_CHILD, ~) \ Chris@16: \ Chris@16: BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE \ Chris@16: static proto_derived_expr const make(Expr const &e) \ Chris@16: { \ Chris@16: proto_derived_expr that = {e}; \ Chris@16: return that; \ Chris@16: } \ Chris@16: \ Chris@16: BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE \ Chris@16: proto_base_expr &proto_base() \ Chris@16: { \ Chris@16: return this->proto_expr_.proto_base(); \ Chris@16: } \ Chris@16: \ Chris@16: BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE \ Chris@16: proto_base_expr const &proto_base() const \ Chris@16: { \ Chris@16: return this->proto_expr_.proto_base(); \ Chris@16: } \ Chris@16: \ Chris@16: BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE \ Chris@16: operator proto_address_of_hack_type_() const \ Chris@16: { \ Chris@16: return boost::addressof(this->proto_base().child0); \ Chris@16: } \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_BASIC_EXTENDS(Expr, Derived, Domain) \ Chris@16: BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, Domain) \ Chris@16: typedef void proto_is_aggregate_; \ Chris@16: /**< INTERNAL ONLY */ Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS_COPY_ASSIGN_IMPL_(This, Const, Typename) \ Chris@16: BOOST_PROTO_DISABLE_MSVC_C4522 \ Chris@16: BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE \ Chris@16: Typename() BOOST_PROTO_RESULT_OF< \ Chris@16: Typename() This::proto_generator( \ Chris@16: Typename() boost::proto::base_expr< \ Chris@16: Typename() This::proto_domain \ Chris@16: , boost::proto::tag::assign \ Chris@16: , boost::proto::list2< \ Chris@16: This & \ Chris@16: , This Const() & \ Chris@16: > \ Chris@16: >::type \ Chris@16: ) \ Chris@16: >::type const \ Chris@16: operator =(This Const() &a) \ Chris@16: { \ Chris@16: typedef \ Chris@16: Typename() boost::proto::base_expr< \ Chris@16: Typename() This::proto_domain \ Chris@16: , boost::proto::tag::assign \ Chris@16: , boost::proto::list2< \ Chris@16: This & \ Chris@16: , This Const() & \ Chris@16: > \ Chris@16: >::type \ Chris@16: that_type; \ Chris@16: that_type const that = { \ Chris@16: *this \ Chris@16: , a \ Chris@16: }; \ Chris@16: return Typename() This::proto_generator()(that); \ Chris@16: } \ Chris@16: /**/ Chris@16: Chris@16: // MSVC 8.0 and higher seem to need copy-assignment operator to be overloaded on *both* Chris@16: // const and non-const rhs arguments. Chris@16: #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600)) && (BOOST_MSVC > 1310) Chris@16: #define BOOST_PROTO_EXTENDS_COPY_ASSIGN_(This, Typename) \ Chris@16: BOOST_PROTO_EXTENDS_COPY_ASSIGN_IMPL_(This, BOOST_PP_EMPTY, Typename) \ Chris@16: BOOST_PROTO_EXTENDS_COPY_ASSIGN_IMPL_(This, BOOST_PROTO_CONST, Typename) \ Chris@16: /**/ Chris@16: #else Chris@16: #define BOOST_PROTO_EXTENDS_COPY_ASSIGN_(This, Typename) \ Chris@16: BOOST_PROTO_EXTENDS_COPY_ASSIGN_IMPL_(This, BOOST_PROTO_CONST, Typename) \ Chris@16: /**/ Chris@16: #endif Chris@16: Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: #define BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(ThisConst, ThatConst) \ Chris@16: template \ Chris@16: BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE \ Chris@16: typename BOOST_PROTO_RESULT_OF< \ Chris@16: proto_generator( \ Chris@16: typename boost::proto::base_expr< \ Chris@16: proto_domain \ Chris@16: , boost::proto::tag::assign \ Chris@16: , boost::proto::list2< \ Chris@16: proto_derived_expr ThisConst() & \ Chris@16: , typename boost::proto::result_of::as_child::type \ Chris@16: > \ Chris@16: >::type \ Chris@16: ) \ Chris@16: >::type const \ Chris@16: operator =(A ThatConst() &a) ThisConst() \ Chris@16: { \ Chris@16: typedef \ Chris@16: typename boost::proto::base_expr< \ Chris@16: proto_domain \ Chris@16: , boost::proto::tag::assign \ Chris@16: , boost::proto::list2< \ Chris@16: proto_derived_expr ThisConst() & \ Chris@16: , typename boost::proto::result_of::as_child::type \ Chris@16: > \ Chris@16: >::type \ Chris@16: that_type; \ Chris@16: that_type const that = { \ Chris@16: *static_cast(this) \ Chris@16: , boost::proto::as_child(a) \ Chris@16: }; \ Chris@16: return proto_generator()(that); \ Chris@16: } \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS_ASSIGN_CONST_() \ Chris@16: BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(BOOST_PROTO_CONST, BOOST_PP_EMPTY) \ Chris@16: BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(BOOST_PROTO_CONST, BOOST_PROTO_CONST) \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST_() \ Chris@16: BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(BOOST_PP_EMPTY, BOOST_PP_EMPTY) \ Chris@16: BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(BOOST_PP_EMPTY, BOOST_PROTO_CONST) \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS_ASSIGN_() \ Chris@16: BOOST_PROTO_EXTENDS_ASSIGN_CONST_() \ Chris@16: BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST_() \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS_ASSIGN_CONST() \ Chris@16: BOOST_PROTO_EXTENDS_COPY_ASSIGN_(proto_derived_expr, BOOST_PROTO_TYPENAME) \ Chris@16: BOOST_PROTO_EXTENDS_ASSIGN_CONST_() \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST() \ Chris@16: BOOST_PROTO_EXTENDS_COPY_ASSIGN_(proto_derived_expr, BOOST_PROTO_TYPENAME) \ Chris@16: BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST_() \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS_ASSIGN() \ Chris@16: BOOST_PROTO_EXTENDS_COPY_ASSIGN_(proto_derived_expr, BOOST_PROTO_TYPENAME) \ Chris@16: BOOST_PROTO_EXTENDS_ASSIGN_() \ Chris@16: /**/ Chris@16: Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: #define BOOST_PROTO_EXTENDS_SUBSCRIPT_IMPL_(ThisConst, ThatConst) \ Chris@16: template \ Chris@16: BOOST_PROTO_DISABLE_MSVC_C4714 BOOST_FORCEINLINE \ Chris@16: typename BOOST_PROTO_RESULT_OF< \ Chris@16: proto_generator( \ Chris@16: typename boost::proto::base_expr< \ Chris@16: proto_domain \ Chris@16: , boost::proto::tag::subscript \ Chris@16: , boost::proto::list2< \ Chris@16: proto_derived_expr ThisConst() & \ Chris@16: , typename boost::proto::result_of::as_child::type \ Chris@16: > \ Chris@16: >::type \ Chris@16: ) \ Chris@16: >::type const \ Chris@16: operator [](A ThatConst() &a) ThisConst() \ Chris@16: { \ Chris@16: typedef \ Chris@16: typename boost::proto::base_expr< \ Chris@16: proto_domain \ Chris@16: , boost::proto::tag::subscript \ Chris@16: , boost::proto::list2< \ Chris@16: proto_derived_expr ThisConst() & \ Chris@16: , typename boost::proto::result_of::as_child::type \ Chris@16: > \ Chris@16: >::type \ Chris@16: that_type; \ Chris@16: that_type const that = { \ Chris@16: *static_cast(this) \ Chris@16: , boost::proto::as_child(a) \ Chris@16: }; \ Chris@16: return proto_generator()(that); \ Chris@16: } \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS_SUBSCRIPT_CONST() \ Chris@16: BOOST_PROTO_EXTENDS_SUBSCRIPT_IMPL_(BOOST_PROTO_CONST, BOOST_PP_EMPTY) \ Chris@16: BOOST_PROTO_EXTENDS_SUBSCRIPT_IMPL_(BOOST_PROTO_CONST, BOOST_PROTO_CONST) \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS_SUBSCRIPT_NON_CONST() \ Chris@16: BOOST_PROTO_EXTENDS_SUBSCRIPT_IMPL_(BOOST_PP_EMPTY, BOOST_PP_EMPTY) \ Chris@16: BOOST_PROTO_EXTENDS_SUBSCRIPT_IMPL_(BOOST_PP_EMPTY, BOOST_PROTO_CONST) \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS_SUBSCRIPT() \ Chris@16: BOOST_PROTO_EXTENDS_SUBSCRIPT_CONST() \ Chris@16: BOOST_PROTO_EXTENDS_SUBSCRIPT_NON_CONST() \ Chris@16: /**/ Chris@16: Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: #define BOOST_PROTO_EXTENDS_FUNCTION_() \ Chris@16: template \ Chris@16: struct result \ Chris@16: { \ Chris@16: typedef \ Chris@16: typename BOOST_PROTO_RESULT_OF< \ Chris@16: proto_generator( \ Chris@16: typename boost::proto::result_of::funop< \ Chris@16: Sig \ Chris@16: , proto_derived_expr \ Chris@16: , proto_domain \ Chris@16: >::type \ Chris@16: ) \ Chris@16: >::type const \ Chris@16: type; \ Chris@16: }; \ Chris@16: /**/ Chris@16: Chris@16: #ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES Chris@16: #define BOOST_PROTO_EXTENDS_FUNCTION_CONST() \ Chris@16: BOOST_PROTO_EXTENDS_FUNCTION_() \ Chris@16: BOOST_PROTO_DEFINE_FUN_OP_VARIADIC_IMPL_(BOOST_PROTO_CONST) \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS_FUNCTION_NON_CONST() \ Chris@16: BOOST_PROTO_EXTENDS_FUNCTION_() \ Chris@16: BOOST_PROTO_DEFINE_FUN_OP_VARIADIC_IMPL_(BOOST_PP_EMPTY) \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS_FUNCTION() \ Chris@16: BOOST_PROTO_EXTENDS_FUNCTION_() \ Chris@16: BOOST_PROTO_DEFINE_FUN_OP_VARIADIC_IMPL_(BOOST_PP_EMPTY) \ Chris@16: BOOST_PROTO_DEFINE_FUN_OP_VARIADIC_IMPL_(BOOST_PROTO_CONST) \ Chris@16: /**/ Chris@16: #else Chris@16: #define BOOST_PROTO_EXTENDS_FUNCTION_CONST() \ Chris@16: BOOST_PROTO_EXTENDS_FUNCTION_() \ Chris@16: BOOST_PP_REPEAT_FROM_TO( \ Chris@16: 0 \ Chris@16: , BOOST_PROTO_MAX_FUNCTION_CALL_ARITY \ Chris@16: , BOOST_PROTO_DEFINE_FUN_OP_CONST \ Chris@16: , ~ \ Chris@16: ) \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS_FUNCTION_NON_CONST() \ Chris@16: BOOST_PROTO_EXTENDS_FUNCTION_() \ Chris@16: BOOST_PP_REPEAT_FROM_TO( \ Chris@16: 0 \ Chris@16: , BOOST_PROTO_MAX_FUNCTION_CALL_ARITY \ Chris@16: , BOOST_PROTO_DEFINE_FUN_OP_NON_CONST \ Chris@16: , ~ \ Chris@16: ) \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS_FUNCTION() \ Chris@16: BOOST_PROTO_EXTENDS_FUNCTION_() \ Chris@16: BOOST_PP_REPEAT_FROM_TO( \ Chris@16: 0 \ Chris@16: , BOOST_PROTO_MAX_FUNCTION_CALL_ARITY \ Chris@16: , BOOST_PROTO_DEFINE_FUN_OP \ Chris@16: , ~ \ Chris@16: ) \ Chris@16: /**/ Chris@16: #endif Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS(Expr, Derived, Domain) \ Chris@16: BOOST_PROTO_BASIC_EXTENDS(Expr, Derived, Domain) \ Chris@16: BOOST_PROTO_EXTENDS_ASSIGN() \ Chris@16: BOOST_PROTO_EXTENDS_SUBSCRIPT() \ Chris@16: BOOST_PROTO_EXTENDS_FUNCTION() \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS_USING_ASSIGN(Derived) \ Chris@16: typedef typename Derived::proto_extends proto_extends; \ Chris@16: using proto_extends::operator =; \ Chris@16: BOOST_PROTO_EXTENDS_COPY_ASSIGN_(Derived, BOOST_PROTO_TYPENAME) \ Chris@16: /**/ Chris@16: Chris@16: #define BOOST_PROTO_EXTENDS_USING_ASSIGN_NON_DEPENDENT(Derived) \ Chris@16: typedef Derived::proto_extends proto_extends; \ Chris@16: using proto_extends::operator =; \ Chris@16: BOOST_PROTO_EXTENDS_COPY_ASSIGN_(Derived, BOOST_PP_EMPTY) \ Chris@16: /**/ Chris@16: Chris@16: namespace exprns_ Chris@16: { Chris@16: /// \brief Empty type to be used as a dummy template parameter of Chris@16: /// POD expression wrappers. It allows argument-dependent lookup Chris@16: /// to find Proto's operator overloads. Chris@16: /// Chris@16: /// \c proto::is_proto_expr allows argument-dependent lookup Chris@16: /// to find Proto's operator overloads. For example: Chris@16: /// Chris@16: /// \code Chris@16: /// template Chris@16: /// struct my_terminal Chris@16: /// { Chris@16: /// BOOST_PROTO_BASIC_EXTENDS( Chris@16: /// typename proto::terminal::type Chris@16: /// , my_terminal Chris@16: /// , default_domain Chris@16: /// ) Chris@16: /// }; Chris@16: /// Chris@16: /// // ... Chris@16: /// my_terminal _1, _2; Chris@16: /// _1 + _2; // OK, uses proto::operator+ Chris@16: /// \endcode Chris@16: /// Chris@16: /// Without the second \c Dummy template parameter, Proto's operator Chris@16: /// overloads would not be considered by name lookup. Chris@16: struct is_proto_expr Chris@16: {}; Chris@16: Chris@16: /// \brief extends\<\> class template for adding behaviors to a Proto expression template Chris@16: /// Chris@16: template< Chris@16: typename Expr Chris@16: , typename Derived Chris@16: , typename Domain // = proto::default_domain Chris@16: , long Arity // = Expr::proto_arity_c Chris@16: > Chris@16: struct extends Chris@16: { Chris@16: BOOST_FORCEINLINE Chris@16: extends() Chris@16: : proto_expr_() Chris@16: {} Chris@16: Chris@16: BOOST_FORCEINLINE Chris@16: extends(extends const &that) Chris@16: : proto_expr_(that.proto_expr_) Chris@16: {} Chris@16: Chris@16: BOOST_FORCEINLINE Chris@16: extends(Expr const &expr_) Chris@16: : proto_expr_(expr_) Chris@16: {} Chris@16: Chris@16: typedef extends proto_extends; Chris@16: BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, typename Domain) Chris@16: BOOST_PROTO_EXTENDS_ASSIGN_CONST_() Chris@16: BOOST_PROTO_EXTENDS_SUBSCRIPT_CONST() Chris@16: Chris@16: // Instead of using BOOST_PROTO_EXTENDS_FUNCTION, which uses Chris@16: // nested preprocessor loops, use file iteration here to generate Chris@16: // the operator() overloads, which is more efficient. Chris@16: #include Chris@16: }; Chris@16: Chris@16: /// \brief extends\<\> class template for adding behaviors to a Proto expression template Chris@16: /// Chris@16: template Chris@16: struct extends Chris@16: { Chris@16: BOOST_FORCEINLINE Chris@16: extends() Chris@16: : proto_expr_() Chris@16: {} Chris@16: Chris@16: BOOST_FORCEINLINE Chris@16: extends(extends const &that) Chris@16: : proto_expr_(that.proto_expr_) Chris@16: {} Chris@16: Chris@16: BOOST_FORCEINLINE Chris@16: extends(Expr const &expr_) Chris@16: : proto_expr_(expr_) Chris@16: {} Chris@16: Chris@16: typedef extends proto_extends; Chris@16: BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, typename Domain) Chris@16: BOOST_PROTO_EXTENDS_ASSIGN_() Chris@16: BOOST_PROTO_EXTENDS_SUBSCRIPT() Chris@16: Chris@16: // Instead of using BOOST_PROTO_EXTENDS_FUNCTION, which uses Chris@16: // nested preprocessor loops, use file iteration here to generate Chris@16: // the operator() overloads, which is more efficient. Chris@16: #include Chris@16: }; Chris@16: Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: template Chris@16: struct virtual_member Chris@16: { Chris@16: typedef Domain proto_domain; Chris@16: typedef typename Domain::proto_generator proto_generator; Chris@16: typedef virtual_member proto_derived_expr; Chris@16: typedef tag::member proto_tag; Chris@16: typedef list2 > const &> proto_args; Chris@16: typedef mpl::long_<2> proto_arity; Chris@16: typedef detail::not_a_valid_type proto_address_of_hack_type_; Chris@16: typedef void proto_is_expr_; /**< INTERNAL ONLY */ Chris@16: static const long proto_arity_c = 2; Chris@16: typedef boost::proto::tag::proto_expr fusion_tag; Chris@16: typedef This &proto_child0; Chris@16: typedef expr > const &proto_child1; Chris@16: typedef expr proto_base_expr; Chris@16: typedef basic_expr proto_grammar; Chris@16: typedef void proto_is_aggregate_; /**< INTERNAL ONLY */ Chris@16: Chris@16: BOOST_PROTO_EXTENDS_ASSIGN_() Chris@16: BOOST_PROTO_EXTENDS_SUBSCRIPT() Chris@16: Chris@16: // Instead of using BOOST_PROTO_EXTENDS_FUNCTION, which uses Chris@16: // nested preprocessor loops, use file iteration here to generate Chris@16: // the operator() overloads, which is more efficient. Chris@16: #define BOOST_PROTO_NO_WAVE_OUTPUT Chris@16: #include Chris@16: #undef BOOST_PROTO_NO_WAVE_OUTPUT Chris@16: Chris@16: BOOST_FORCEINLINE Chris@16: proto_base_expr const proto_base() const Chris@16: { Chris@16: proto_base_expr that = {this->child0(), this->child1()}; Chris@16: return that; Chris@16: } Chris@16: Chris@16: BOOST_FORCEINLINE Chris@16: proto_child0 child0() const Chris@16: { Chris@16: using std::size_t; Chris@16: return *(This *)((char *)this - BOOST_PROTO_OFFSETOF(This, proto_member_union_start_)); Chris@16: } Chris@16: Chris@16: BOOST_FORCEINLINE Chris@16: proto_child1 child1() const Chris@16: { Chris@16: static expr, 0> const that = {Fun()}; Chris@16: return that; Chris@16: } Chris@16: }; Chris@16: Chris@16: /// INTERNAL ONLY Chris@16: /// Chris@16: #define BOOST_PROTO_EXTENDS_MEMBER_(R, DOMAIN, ELEM) \ Chris@16: boost::proto::exprns_::virtual_member< \ Chris@16: proto_derived_expr \ Chris@16: , BOOST_PP_TUPLE_ELEM(2, 0, ELEM) \ Chris@16: , DOMAIN \ Chris@16: > BOOST_PP_TUPLE_ELEM(2, 1, ELEM); \ Chris@16: /**/ Chris@16: Chris@16: /// \brief For declaring virtual data members in an extension class. Chris@16: /// Chris@16: #define BOOST_PROTO_EXTENDS_MEMBERS_WITH_DOMAIN(SEQ, DOMAIN) \ Chris@16: union \ Chris@16: { \ Chris@16: char proto_member_union_start_; \ Chris@16: BOOST_PP_SEQ_FOR_EACH(BOOST_PROTO_EXTENDS_MEMBER_, DOMAIN, SEQ) \ Chris@16: }; \ Chris@16: /**/ Chris@16: Chris@16: /// \brief For declaring virtual data members in an extension class. Chris@16: /// Chris@16: #define BOOST_PROTO_EXTENDS_MEMBERS(SEQ) \ Chris@16: BOOST_PROTO_EXTENDS_MEMBERS_WITH_DOMAIN(SEQ, proto_domain) \ Chris@16: /**/ Chris@16: Chris@16: } Chris@16: Chris@16: }} Chris@16: Chris@101: #if defined(_MSC_VER) Chris@16: # pragma warning(pop) Chris@16: #endif Chris@16: Chris@16: #endif