lambda.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 1,675 行 · 第 1/5 页
HPP
1,675 行
namespace exprns_ { // Ugh, the assign operators (and only the assign operators) store // their left terminals by reference. That requires this special handling. #define BOOST_LAMBDA_DEFINE_ASSIGN_OP(OP, TAG) \ template<typename T, typename U> \ typename proto::result_of::make_expr< \ TAG \ , lldomain \ , typename byref<T>::type \ , U & \ >::type const \ operator OP(T &t, U &u) \ { \ return proto::implicit_expr(t, u); \ } \ template<typename T, typename U> \ typename proto::result_of::make_expr< \ TAG \ , lldomain \ , typename byref<T>::type \ , U const & \ >::type const \ operator OP(T &t, U const &u) \ { \ return proto::implicit_expr(t, u); \ } \ /**/ BOOST_LAMBDA_DEFINE_ASSIGN_OP(<<=, boost::proto::tag::shift_left_assign) BOOST_LAMBDA_DEFINE_ASSIGN_OP(>>=, boost::proto::tag::shift_right_assign) BOOST_LAMBDA_DEFINE_ASSIGN_OP(*= , boost::proto::tag::multiplies_assign) BOOST_LAMBDA_DEFINE_ASSIGN_OP(/= , boost::proto::tag::divides_assign) BOOST_LAMBDA_DEFINE_ASSIGN_OP(%= , boost::proto::tag::modulus_assign) BOOST_LAMBDA_DEFINE_ASSIGN_OP(+= , boost::proto::tag::plus_assign) BOOST_LAMBDA_DEFINE_ASSIGN_OP(-= , boost::proto::tag::minus_assign) BOOST_LAMBDA_DEFINE_ASSIGN_OP(&= , boost::proto::tag::bitwise_and_assign) BOOST_LAMBDA_DEFINE_ASSIGN_OP(|= , boost::proto::tag::bitwise_or_assign) BOOST_LAMBDA_DEFINE_ASSIGN_OP(^= , boost::proto::tag::bitwise_xor_assign) } template<typename T> struct var_type { typedef llexpr<typename proto::terminal<T &>::type> type; }; template<typename T> llexpr<typename proto::terminal<T &>::type> const var(T &t) { return proto::implicit_expr(t); } template<typename T> struct constant_type : proto::result_of::make_expr< proto::tag::terminal , lldomain , T const & > {}; template<typename T> typename constant_type<T>::type const constant(T const &t) { return proto::implicit_expr(t); } template<typename T> struct constant_ref_type { typedef llexpr<typename proto::terminal<T const &>::type> type; }; template<typename T> llexpr<typename proto::terminal<T const &>::type> const constant_ref(T const &t) { return proto::implicit_expr(t); } template<typename Cond> struct while_generator { explicit while_generator(Cond const &c) : cond(c) {} template<typename Body> typename proto::result_of::make_expr< tag::while_ , lldomain , Cond const & , Body const & >::type const operator[](Body const &body) const { return proto::implicit_expr(this->cond, body); } private: Cond const &cond; }; template<typename Expr> while_generator<Expr> while_(Expr const &expr) { return while_generator<Expr>(expr); } template<typename Expr> struct else_generator { typedef typename proto::result_of::left<Expr const &>::type condition_type; typedef typename proto::result_of::right<Expr const &>::type body1_type; explicit else_generator(Expr const &expr) : if_(expr) {} template<typename Body2> typename proto::result_of::make_expr< tag::if_else_ , lldomain , condition_type , body1_type , Body2 const & >::type const operator[](Body2 const &body2) const { return proto::implicit_expr(proto::left(this->if_), proto::right(this->if_), body2); } private: Expr const &if_; }; template<typename Expr> struct with_else : Expr { template<typename T> with_else(T const &expr) : Expr(expr) , else_(*this) {} else_generator<Expr> else_; }; template<typename Cond> struct if_generator { explicit if_generator(Cond const &c) : cond(c) {} template<typename Body> with_else< typename proto::result_of::make_expr< tag::if_ , lldomain , Cond const & , Body const & >::type > const operator[](Body const &body) const { return proto::implicit_expr(this->cond, body); } private: Cond const &cond; }; template<typename Expr> if_generator<Expr> if_(Expr const &expr) { return if_generator<Expr>(expr); } template<typename Init, typename Cond, typename Oper> struct for_generator { explicit for_generator(Init const &i, Cond const &c, Oper const &o) : init(i) , cond(c) , oper(o) {} template<typename Body> typename proto::result_of::make_expr< tag::for_ , lldomain , Init const & , Cond const & , Oper const & , Body const & >::type const operator[](Body const &body) const { return proto::implicit_expr(this->init, this->cond, this->oper, body); } private: Init const &init; Cond const &cond; Oper const &oper; }; template<typename Init, typename Cond, typename Oper> for_generator<Init, Cond, Oper> for_(Init const &i, Cond const &c, Oper const &o) { return for_generator<Init, Cond, Oper>(i, c, o); } template<typename Body> struct do_while_generator { explicit do_while_generator(Body const &b) : body(b) {} template<typename Cond> typename proto::result_of::make_expr< tag::do_while_ , lldomain , Body const & , Cond const & >::type const operator()(Cond const &cond) const { return proto::implicit_expr(this->body, cond); } private: Body const &body; }; template<typename Body> struct do_body { explicit do_body(Body const &body) : while_(body) {} do_while_generator<Body> while_; }; struct do_generator { template<typename Body> do_body<Body> operator[](Body const &body) const { return do_body<Body>(body); } }; do_generator const do_ = {}; struct noop_fun { typedef void result_type; void operator()() const {} }; typedef llexpr<proto::function<llexpr<proto::terminal<noop_fun>::type> >::type> noop_type; noop_type const noop = {{{{{}}}}}; template<typename Init, typename Cond, typename Oper> typename proto::result_of::make_expr< tag::for_ , lldomain , Init const & , Cond const & , Oper const & , noop_type const & >::type const for_loop(Init const &init, Cond const &cond, Oper const &oper) { return proto::implicit_expr(init, cond, oper, noop); } template<typename Init, typename Cond, typename Oper, typename Body> typename proto::result_of::make_expr< tag::for_ , lldomain , Init const & , Cond const & , Oper const & , Body const & >::type const for_loop(Init const &init, Cond const &cond, Oper const &oper, Body const &body) { return proto::implicit_expr(init, cond, oper, body); } template<typename Cond, typename Body> typename proto::result_of::make_expr< tag::while_ , lldomain , Cond const & , Body const & >::type const while_loop(Cond const &cond, Body const &body) { return proto::implicit_expr(cond, body); } template<typename Cond> typename proto::result_of::make_expr< tag::while_ , lldomain , Cond const & , noop_type const & >::type const while_loop(Cond const &cond) { return proto::implicit_expr(cond, noop); } template<typename Cond, typename Body> typename proto::result_of::make_expr< tag::do_while_ , lldomain , Body const & , Cond const & >::type const do_while_loop(Cond const &cond, Body const &body) { return proto::implicit_expr(body, cond); } template<typename Cond>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?