📄 fold.hpp
字号:
#ifndef BOOST_PP_IS_ITERATING /////////////////////////////////////////////////////////////////////////////// /// \file fold.hpp /// Contains definition of the fold<> and reverse_fold<> transforms. // // Copyright 2008 Eric Niebler. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_PROTO_TRANSFORM_FOLD_HPP_EAN_11_04_2007 #define BOOST_PROTO_TRANSFORM_FOLD_HPP_EAN_11_04_2007 #include <boost/proto/detail/prefix.hpp> #include <boost/version.hpp> #include <boost/preprocessor/cat.hpp> #include <boost/preprocessor/iteration/iterate.hpp> #include <boost/preprocessor/arithmetic/inc.hpp> #include <boost/preprocessor/arithmetic/sub.hpp> #include <boost/preprocessor/repetition/repeat.hpp> #if BOOST_VERSION >= 103500 #include <boost/fusion/include/fold.hpp> #else #include <boost/spirit/fusion/algorithm/fold.hpp> #endif #include <boost/proto/proto_fwd.hpp> #include <boost/proto/fusion.hpp> #include <boost/proto/traits.hpp> #include <boost/proto/transform/call.hpp> #include <boost/proto/transform/impl.hpp> #include <boost/proto/detail/suffix.hpp> namespace boost { namespace proto { namespace detail { template<typename Transform, typename Data> struct as_callable { as_callable(Data v) : v_(v) {} template<typename Sig> struct result; template<typename This, typename Expr, typename State> struct result<This(Expr, State)> { typedef typename when<_, Transform>::template impl<Expr, State, Data>::result_type type; }; #if BOOST_VERSION < 103500 template<typename Expr, typename State> struct apply : result<void(Expr, State)> {}; #endif template<typename Expr, typename State> typename when<_, Transform>::template impl<Expr &, State const &, Data>::result_type operator ()(Expr &expr, State const &state) const { return typename when<_, Transform>::template impl<Expr &, State const &, Data>()(expr, state, this->v_); } private: Data v_; }; #if BOOST_VERSION < 103500 template<typename Sequence, typename Void = void> struct as_fusion_sequence_type { typedef Sequence const type; }; template<typename Sequence> Sequence const &as_fusion_sequence(Sequence const &sequence, ...) { return sequence; } template<typename Sequence> struct as_fusion_sequence_type<Sequence, typename Sequence::proto_is_expr_> { typedef typename Sequence::proto_base_expr const type; }; template<typename Sequence> typename Sequence::proto_base_expr const &as_fusion_sequence(Sequence const &sequence, int) { return sequence.proto_base(); } #define BOOST_PROTO_AS_FUSION_SEQUENCE_TYPE(X) typename detail::as_fusion_sequence_type<X>::type #define BOOST_PROTO_AS_FUSION_SEQUENCE(X) detail::as_fusion_sequence(X, 0) #else #define BOOST_PROTO_AS_FUSION_SEQUENCE_TYPE(X) X #define BOOST_PROTO_AS_FUSION_SEQUENCE(X) X #endif template< typename State0 , typename Fun , typename Expr , typename State , typename Data , long Arity = arity_of<Expr>::value > struct fold_impl {}; template< typename State0 , typename Fun , typename Expr , typename State , typename Data , long Arity = arity_of<Expr>::value > struct reverse_fold_impl {}; #define BOOST_PROTO_CHILD_N_TYPE(N)\ BOOST_PP_CAT(proto_child, N)\ /**/ #define BOOST_PROTO_FOLD_STATE_TYPE(Z, N, DATA) \ typedef \ typename when<_, Fun>::template impl< \ typename result_of::child_c<Expr, N>::type \ , BOOST_PP_CAT(state, N) \ , Data \ >::result_type \ BOOST_PP_CAT(state, BOOST_PP_INC(N)); \ /**/ #define BOOST_PROTO_FOLD_STATE(Z, N, DATA) \ BOOST_PP_CAT(state, BOOST_PP_INC(N)) \ BOOST_PP_CAT(s, BOOST_PP_INC(N)) \ = typename when<_, Fun>::template impl< \ typename result_of::child_c<Expr, N>::type \ , BOOST_PP_CAT(state, N) \ , Data \ >()( \ proto::child_c<N>(expr) \ , BOOST_PP_CAT(s, N) \ , data \ ); \ /**/ #define BOOST_PROTO_REVERSE_FOLD_STATE_TYPE(Z, N, DATA) \ typedef \ typename when<_, Fun>::template impl< \ typename result_of::child_c< \ Expr \ , BOOST_PP_SUB(DATA, BOOST_PP_INC(N)) \ >::type \ , BOOST_PP_CAT(state, BOOST_PP_SUB(DATA, N)) \ , Data \ >::result_type \ BOOST_PP_CAT(state, BOOST_PP_SUB(DATA, BOOST_PP_INC(N))); \ /**/ #define BOOST_PROTO_REVERSE_FOLD_STATE(Z, N, DATA) \ BOOST_PP_CAT(state, BOOST_PP_SUB(DATA, BOOST_PP_INC(N))) \ BOOST_PP_CAT(s, BOOST_PP_SUB(DATA, BOOST_PP_INC(N))) \ = typename when<_, Fun>::template impl< \ typename result_of::child_c< \ Expr \ , BOOST_PP_SUB(DATA, BOOST_PP_INC(N)) \ >::type \ , BOOST_PP_CAT(state, BOOST_PP_SUB(DATA, N)) \ , Data \ >()( \ proto::child_c<BOOST_PP_SUB(DATA, BOOST_PP_INC(N))>(expr) \ , BOOST_PP_CAT(s, BOOST_PP_SUB(DATA, N)) \ , data \ ); \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -