lambda.hpp

来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 1,675 行 · 第 1/5 页

HPP
1,675
字号
                            Expr                          , proto::arity_of<Expr>::value-1                        >::type                    >::type                >            {};        };        struct throw_fun        {            BOOST_PROTO_CALLABLE()            typedef void result_type;            template<typename Expr>            void operator()(Expr const &e) const            {                throw e;            }        };                struct unwrap_ref : proto::callable        {            template<typename Sig>            struct result;                        template<typename This, typename T>            struct result<This(reference_wrapper<T>)>            {                typedef T &type;                            };                        template<typename This, typename T>            struct result<This(T &)>              : result<This(T)>            {};                        template<typename T>            T &operator()(reference_wrapper<T> const &ref) const            {                return ref;            }        };        struct anytype        {            template<typename T>            anytype(T &) { BOOST_ASSERT(false); }            template<typename T>            operator T &() const { BOOST_ASSERT(false); throw; }        private:            anytype();        };        struct rethrow_fun        {            BOOST_PROTO_CALLABLE()            typedef anytype result_type;            template<typename State>            anytype operator()(State const &) const            {                BOOST_MPL_ASSERT_NOT((is_same<State, no_exception_type>));                throw;            }        };        struct Cases        {            template<typename Tag>            struct case_              : proto::otherwise<proto::_default<Eval> >            {};            template<typename E>            struct case_<tag::catch_<E> >              : proto::otherwise<Eval(proto::_child)>            {};            template<int I>            struct case_<tag::case_<I> >              : proto::otherwise<Eval(proto::_child)>            {};        };        template<> struct Cases::case_<tag::while_>     : proto::otherwise<EvalWhile> {};        template<> struct Cases::case_<tag::for_>       : proto::otherwise<EvalFor> {};        template<> struct Cases::case_<tag::if_>        : proto::otherwise<EvalIf> {};        template<> struct Cases::case_<tag::if_else_>   : proto::otherwise<EvalIfElse> {};        template<> struct Cases::case_<tag::do_while_>  : proto::otherwise<EvalDoWhile> {};        template<> struct Cases::case_<tag::switch_>    : proto::otherwise<EvalSwitch> {};        template<> struct Cases::case_<tag::protect>    : proto::otherwise<proto::_child> {};        template<> struct Cases::case_<tag::default_>   : proto::otherwise<Eval(proto::_child)> {};        template<> struct Cases::case_<tag::catch_all_> : proto::otherwise<Eval(proto::_child)> {};        template<>        struct Cases::case_<proto::tag::terminal>          : proto::or_<                proto::when<                    proto::terminal<placeholder<proto::_> >                  , at(proto::_data, proto::_value)                >              , proto::when<                    proto::terminal<exception_placeholder>                  , EvalException                >              , proto::when<                    proto::terminal<reference_wrapper<proto::_> >                  , unwrap_ref(proto::_value)                >              , proto::otherwise<proto::_default<Eval> >            >        {};        template<>        struct Cases::case_<proto::tag::function>          : proto::or_<                proto::when<                    proto::function<proto::terminal<rethrow_fun> >                  , rethrow_fun(proto::_state)                >              , proto::otherwise<proto::_default<Eval> >            >        {};        struct Eval          : proto::switch_<Cases>        {};        // Use a grammar to disable Proto's assignment operator overloads.        // We'll define our own because we want (x+=_1) to store x by        // reference. (In all other cases, variables are stored by value        // within lambda expressions.)        struct Grammar          : proto::switch_<struct AssignOps>        {};        struct AssignOps        {            template<typename Tag> struct case_ : proto::_ {};        };        template<> struct AssignOps::case_<proto::tag::shift_left_assign>   : proto::not_<proto::_> {};        template<> struct AssignOps::case_<proto::tag::shift_right_assign>  : proto::not_<proto::_> {};        template<> struct AssignOps::case_<proto::tag::multiplies_assign>   : proto::not_<proto::_> {};        template<> struct AssignOps::case_<proto::tag::divides_assign>      : proto::not_<proto::_> {};        template<> struct AssignOps::case_<proto::tag::modulus_assign>      : proto::not_<proto::_> {};        template<> struct AssignOps::case_<proto::tag::plus_assign>         : proto::not_<proto::_> {};        template<> struct AssignOps::case_<proto::tag::minus_assign>        : proto::not_<proto::_> {};        template<> struct AssignOps::case_<proto::tag::bitwise_and_assign>  : proto::not_<proto::_> {};        template<> struct AssignOps::case_<proto::tag::bitwise_or_assign>   : proto::not_<proto::_> {};        template<> struct AssignOps::case_<proto::tag::bitwise_xor_assign>  : proto::not_<proto::_> {};        namespace exprns_        {            template<typename Expr>            struct llexpr;        }        using exprns_::llexpr;        template<typename T>        struct is_stream        {        private:            static T &t;            typedef char yes_type;            typedef char (&no_type)[2];            static no_type test_is_stream(...);            template<typename Char, typename Traits>            static yes_type test_is_stream(std::basic_istream<Char, Traits> &);            template<typename Char, typename Traits>            static yes_type test_is_stream(std::basic_ostream<Char, Traits> &);        public:            typedef bool value_type;            BOOST_STATIC_CONSTANT(bool, value = sizeof(yes_type) == sizeof(test_is_stream(t)));            typedef mpl::bool_<value> type;        };        // These terminal types are always stored by reference        template<typename Value>        struct store_by_ref          : mpl::or_<                is_abstract<Value>              , is_array<Value>              , is_function<Value>              , is_stream<Value>            >        {};        // Wrap expressions in lambda::llexpr<>, and hold children nodes        // and some terminal types by value.        struct Generator          : proto::or_<                proto::when<                    proto::and_<                        proto::terminal<proto::_>                      , proto::if_<store_by_ref<proto::_value>()>                    >                  , proto::pod_generator<llexpr>(proto::_)                >              , proto::otherwise<                    proto::compose_generators<                        proto::by_value_generator                      , proto::pod_generator<llexpr>                    >(proto::_)                >            >        {};        struct lldomain          : proto::domain<Generator, Grammar>        {};        template<typename Sig>        struct llresult;        template<typename This>        struct llresult<This()>          : mpl::if_c<                result_of<IsNullary(This &)>::type::value              , result_of<Eval(This &, no_exception_type const &, fusion::vector0 &)>              , mpl::identity<void>            >::type        {};        #define M0(Z, N, DATA)                                                                      \        template<typename This BOOST_PP_ENUM_TRAILING_PARAMS_Z(Z, N, typename A)>                   \        struct llresult<This(BOOST_PP_ENUM_PARAMS_Z(Z, N, A))>                                      \          : result_of<                                                                              \                Eval(                                                                               \                    This &                                                                          \                  , no_exception_type const &                                                       \                  , BOOST_PP_CAT(fusion::vector, N)<BOOST_PP_ENUM_PARAMS_Z(Z, N, A)> &              \                )                                                                                   \            >                                                                                       \        {};                                                                                         \        /**/        BOOST_PP_REPEAT_FROM_TO(1, BOOST_PP_INC(BOOST_LAMBDA_MAX_ARITY), M0, ~)        #undef M0        template<typename Expr>        struct llexpr        {            BOOST_PROTO_BASIC_EXTENDS(Expr, llexpr<Expr>, lldomain)            BOOST_PROTO_EXTENDS_ASSIGN()            BOOST_PROTO_EXTENDS_SUBSCRIPT()            template<typename Sig>            struct result              : llresult<Sig>            {};            typename result<Expr const()>::type            operator()() const            {                fusion::vector0 args;                return Eval()(*this, no_exception, args);            }            #define M1(Z, N, _) ((0)(1))            #define M2(R, PRODUCT) M3(R, BOOST_PP_SEQ_SIZE(PRODUCT), PRODUCT)            #define M3(R, SIZE, PRODUCT)                                                                    \                template<BOOST_PP_ENUM_PARAMS(SIZE, typename A)>                                            \                typename result<Expr const(BOOST_PP_SEQ_FOR_EACH_I_R(R, M5, ~, PRODUCT))>::type             \                operator ()(BOOST_PP_SEQ_FOR_EACH_I_R(R, M4, ~, PRODUCT)) const                             \                {                                                                                           \                    BOOST_MPL_ASSERT_RELATION(result_of<Arity(Expr const &)>::type::value, <=, SIZE);       \                    BOOST_PP_CAT(fusion::vector, SIZE)<BOOST_PP_SEQ_FOR_EACH_I_R(R, M5, ~, PRODUCT)> args   \                        (BOOST_PP_SEQ_FOR_EACH_I_R(R, M6, ~, PRODUCT));                                     \                    return Eval()(*this, no_exception, args);                                               \                }                                                                                           \                /**/            #define M4(R, _, I, ELEM)                                                                       \                BOOST_PP_COMMA_IF(I) BOOST_PP_CAT(A, I) BOOST_PP_CAT(C, ELEM) &BOOST_PP_CAT(a, I)           \                /**/            #define M5(R, _, I, ELEM)                                                                       \                BOOST_PP_COMMA_IF(I) BOOST_PP_CAT(A, I) BOOST_PP_CAT(C, ELEM)&                              \                /**/            #define M6(R, _, I, ELEM)                                                                       \                BOOST_PP_COMMA_IF(I) BOOST_PP_CAT(a, I)                                                     \                /**/            #define C0            #define C1 const            #define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_LAMBDA_MAX_ARITY, <boost/lambda2/lambda.hpp>))            #include BOOST_PP_ITERATE()            #undef C0            #undef C1            #undef M1            #undef M2            #undef M3            #undef M4            #undef M5            #undef M6        };        typedef llexpr<proto::terminal<placeholder<mpl::int_<0> > >::type> placeholder1_type;        typedef llexpr<proto::terminal<placeholder<mpl::int_<1> > >::type> placeholder2_type;        typedef llexpr<proto::terminal<placeholder<mpl::int_<2> > >::type> placeholder3_type;        placeholder1_type const _1 = {{{}}};        placeholder2_type const _2 = {{{}}};        placeholder3_type const _3 = {{{}}};        placeholder1_type const free1 = {{{}}};        placeholder2_type const free2 = {{{}}};        placeholder3_type const free3 = {{{}}};        typedef llexpr<proto::terminal<exception_placeholder>::type> placeholderE_type;        placeholderE_type const _e = {{{}}};        template<typename T>        struct byref        {            typedef llexpr<typename proto::terminal<T &>::type> type;        };        template<typename T>        struct byref<llexpr<T> >        {            typedef llexpr<T> &type;        };        template<typename T>        struct byref<llexpr<T> const>        {            typedef llexpr<T> const &type;        };

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?