lambda.hpp

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

HPP
1,675
字号
        };        struct destructor        {            typedef void result_type;            template<typename T>            void operator()(T const &t) const            {                t.~T();            }            template<typename T>            void operator()(T *const &t) const            {                (*t).~T();            }        };        struct delete_ptr        {            typedef void result_type;            template<typename T>            void operator()(T *t) const            {                delete t;            }        };        template<typename T>        struct new_array        {            typedef T *result_type;            T *operator()(std::size_t n) const            {                return new T[n];            }        };        struct delete_array        {            typedef void result_type;            template<typename T>            void operator()(T *t) const            {                delete[] t;            }        };        template<typename T>        struct type2type {};        struct try_catch_nil {};        template<typename Head, typename Tail>        struct try_catch_cons : Tail        {            typedef typename Head::proto_tag::exception_type exception_type;            try_catch_cons(Head const &head, Tail const &tail)              : Tail(tail)              , head(head)            {}            template<typename State, typename Data>            typename result_of<Tail const(State const &, Data &)>::type            operator()(State const &state, Data &data) const            {                return this->invoke(state, data, type2type<exception_type>());            }        private:            // catch(Exception const &)            template<typename State, typename Data, typename Exception>            typename result_of<Tail const(State const &, Data &)>::type            invoke(State const &state, Data &data, type2type<Exception>) const            {                typedef typename result_of<Tail const(State const &, Data &)>::type result_type;                try                {                    return static_cast<result_type>(this->Tail::operator()(state, data));                }                catch(Exception const &e)                {                    return static_cast<result_type>(Eval()(this->head, e, data));                }            }            // catch(...)            template<typename State, typename Data>            typename result_of<Tail const(State const &, Data &)>::type            invoke(State const &state, Data &data, type2type<tag::catch_all_>) const            {                typedef typename result_of<Tail const(State const &, Data &)>::type result_type;                try                {                    return static_cast<result_type>(this->Tail::operator()(state, data));                }                catch(...)                {                    return static_cast<result_type>(Eval()(this->head, tag::catch_all_(), data));                }            }            Head const &head;        };        template<typename Head>        struct try_catch_cons<Head, try_catch_nil> : proto::callable        {            try_catch_cons(Head const &head, try_catch_nil const &)              : head(head)            {}            template<typename Sig>            struct result;            template<typename This, typename State, typename Data>            struct result<This(State, Data)>              : result_of<Eval(Head const &, State, Data)>            {};            template<typename State, typename Data>            typename result_of<Eval(Head const &, State, Data)>::type            operator()(State const &state, Data &data) const            {                return Eval()(this->head, state, data);            }        private:            Head const &head;        };        struct try_catch_fun : proto::callable        {            template<typename Sig>            struct result;            template<typename This, typename Fun, typename State, typename Data>            struct result<This(Fun, State, Data)>              : result_of<Fun(State, Data)>            {};            template<typename Fun, typename State, typename Data>            typename result_of<Fun(State const &, Data &)>::type            operator()(Fun const &fun, State const &state, Data &data) const            {                return fun(state, data);            }        };        template<>        struct Cases::case_<tag::try_>          : proto::otherwise<                try_catch_fun(                    proto::fold<                        proto::_                      , try_catch_nil()                      , try_catch_cons<proto::_, proto::_state>(proto::_, proto::_state)                    >                  , proto::_state                  , proto::_data                )            >        {};        template<typename E, typename Expr>        typename proto::result_of::make_expr<tag::catch_<E>, lldomain, Expr const &>::type const        catch_exception(Expr const &expr)        {            return proto::implicit_expr(expr);        }        template<typename E>        typename proto::result_of::make_expr<tag::catch_<E>, lldomain, noop_type const &>::type const        catch_exception()        {            return proto::implicit_expr(noop);        }        template<typename Expr>        typename proto::result_of::make_expr<            tag::catch_all_          , lldomain          , Expr const &        >::type const        catch_all(Expr const &expr)        {            return proto::implicit_expr(expr);        }        inline        proto::result_of::make_expr<tag::catch_all_, lldomain, noop_type const &>::type const        catch_all()        {            return proto::implicit_expr(noop);        }        #define M1(Z, N, DATA)                                                                      \        template<BOOST_PP_ENUM_PARAMS_Z(Z, N, typename A)>                                          \        typename proto::result_of::make_expr<                                                       \            tag::try_                                                                               \          , lldomain                                                                                \            BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(Z, N, A, const & BOOST_PP_INTERCEPT)             \        >::type const                                                                               \        try_catch(BOOST_PP_ENUM_BINARY_PARAMS_Z(Z, N, A, const & a))                                \        {                                                                                           \            return proto::implicit_expr(BOOST_PP_ENUM_PARAMS_Z(Z, N, a));                           \        }                                                                                           \        /**/        BOOST_PP_REPEAT_FROM_TO(2, BOOST_PP_INC(BOOST_PROTO_MAX_ARITY), M1, ~)        #undef M1        template<typename Expr>        typename proto::result_of::make_expr<            proto::tag::function          , lldomain          , throw_fun          , Expr const &        >::type const        throw_exception(Expr const &expr)        {            throw_fun fun;            return proto::implicit_expr(fun, expr);        }        inline        proto::result_of::make_expr<proto::tag::function, lldomain, rethrow_fun>::type const        rethrow()        {            rethrow_fun fun;            return proto::implicit_expr(fun);        }        struct make_void_fun        {            typedef void result_type;            template<typename T>            void operator()(T const &) const            {}        };        template<typename Expr>        typename proto::result_of::make_expr<            proto::tag::function          , lldomain          , make_void_fun          , Expr const &        >::type const        make_void(Expr const &expr)        {            make_void_fun fun;            return proto::implicit_expr(fun, expr);        }        #define M1(Z, N, DATA)                                                                      \        template<BOOST_PP_ENUM_PARAMS_Z(Z, N, typename A)>                                          \        typename proto::result_of::make_expr<                                                       \            tag::switch_                                                                            \          , lldomain                                                                                \            BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(Z, N, A, const & BOOST_PP_INTERCEPT)             \        >::type const                                                                               \        switch_statement(BOOST_PP_ENUM_BINARY_PARAMS_Z(Z, N, A, const & a))                         \        {                                                                                           \            return proto::implicit_expr(BOOST_PP_ENUM_PARAMS_Z(Z, N, a));                           \        }                                                                                           \        /**/        BOOST_PP_REPEAT_FROM_TO(2, BOOST_PP_INC(BOOST_PROTO_MAX_ARITY), M1, ~)        #undef M1        template<int I, typename Expr>        typename proto::result_of::make_expr<tag::case_<I>, lldomain, Expr const &>::type const        case_statement(Expr const &expr)        {            return proto::implicit_expr(expr);        }        template<int I>        typename proto::result_of::make_expr<tag::case_<I>, lldomain, noop_type const &>::type const        case_statement()        {            return proto::implicit_expr(noop);        }        template<typename Expr>        typename proto::result_of::make_expr<tag::default_, lldomain, Expr const &>::type const        default_statement(Expr const &expr)        {            return proto::implicit_expr(expr);        }        inline        proto::result_of::make_expr<tag::default_, lldomain, noop_type const &>::type const        default_statement()        {            return proto::implicit_expr(noop);        }        namespace ll        {            struct for_each            {                template<typename Sig>                struct result;                template<typename This, typename Begin, typename End, typename Fun>                struct result<This(Begin, End, Fun)>                  : remove_const<typename remove_reference<Fun>::type>                {};                template<typename InIter, typename Fun>                Fun operator()(InIter begin, InIter end, Fun fun) const                {                    return std::for_each(begin, end, fun);                }            };        }    }}    #ifdef _MSC_VER    # pragma warning(pop)    #endif    #endif#else    BOOST_PP_SEQ_FOR_EACH_PRODUCT(        M2,        BOOST_PP_REPEAT(BOOST_PP_ITERATION(), M1, ~)    )#endif

⌨️ 快捷键说明

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