default.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 435 行 · 第 1/2 页
HPP
435 行
#ifndef BOOST_PP_IS_ITERATING /////////////////////////////////////////////////////////////////////////////// /// \file default.hpp /// Definintion of default_context, a default evaluation context for /// proto::eval() that uses Boost.Typeof to deduce return types /// of the built-in operators. // // 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_CONTEXT_DEFAULT_HPP_EAN_01_08_2007 #define BOOST_PROTO_CONTEXT_DEFAULT_HPP_EAN_01_08_2007 #include <boost/proto/detail/prefix.hpp> // must be first include #include <boost/config.hpp> #include <boost/preprocessor/iteration/iterate.hpp> #include <boost/preprocessor/repetition/enum_shifted.hpp> #include <boost/utility/result_of.hpp> #include <boost/type_traits/is_const.hpp> #include <boost/type_traits/is_function.hpp> #include <boost/type_traits/remove_reference.hpp> #include <boost/type_traits/is_member_pointer.hpp> #include <boost/type_traits/is_member_object_pointer.hpp> #include <boost/type_traits/is_member_function_pointer.hpp> #include <boost/proto/proto_fwd.hpp> #include <boost/proto/tags.hpp> #include <boost/proto/eval.hpp> #include <boost/proto/traits.hpp> // for proto::child_c() #include <boost/proto/detail/decltype.hpp> #include <boost/proto/detail/suffix.hpp> // must be last include namespace boost { namespace proto { /// INTERNAL ONLY /// #define UNREF(x) typename boost::remove_reference<x>::type namespace context { template< typename Expr , typename Context , typename Tag BOOST_PROTO_WHEN_BUILDING_DOCS(= typename Expr::proto_tag) , long Arity BOOST_PROTO_WHEN_BUILDING_DOCS(= Expr::proto_arity::value) > struct default_eval {}; /// INTERNAL ONLY /// #define BOOST_PROTO_UNARY_OP_RESULT(OP, TAG, MAKE) \ template<typename Expr, typename Context> \ struct default_eval<Expr, Context, TAG, 1> \ { \ private: \ typedef typename proto::result_of::child_c<Expr, 0>::type e0; \ typedef typename proto::result_of::eval<UNREF(e0), Context>::type r0; \ public: \ BOOST_PROTO_DECLTYPE_(OP proto::detail::MAKE<r0>(), result_type) \ result_type operator ()(Expr &expr, Context &ctx) const \ { \ return OP proto::eval(proto::child_c<0>(expr), ctx); \ } \ }; \ /**/ /// INTERNAL ONLY /// #define BOOST_PROTO_BINARY_OP_RESULT(OP, TAG, LMAKE, RMAKE) \ template<typename Expr, typename Context> \ struct default_eval<Expr, Context, TAG, 2> \ { \ private: \ typedef typename proto::result_of::child_c<Expr, 0>::type e0; \ typedef typename proto::result_of::child_c<Expr, 1>::type e1; \ typedef typename proto::result_of::eval<UNREF(e0), Context>::type r0; \ typedef typename proto::result_of::eval<UNREF(e1), Context>::type r1; \ public: \ BOOST_PROTO_DECLTYPE_( \ proto::detail::LMAKE<r0>() OP proto::detail::RMAKE<r1>() \ , result_type \ ) \ result_type operator ()(Expr &expr, Context &ctx) const \ { \ return proto::eval( \ proto::child_c<0>(expr), ctx) OP proto::eval(proto::child_c<1>(expr) \ , ctx \ ); \ } \ }; \ /**/ BOOST_PROTO_UNARY_OP_RESULT(+, proto::tag::unary_plus, make) BOOST_PROTO_UNARY_OP_RESULT(-, proto::tag::negate, make) BOOST_PROTO_UNARY_OP_RESULT(*, proto::tag::dereference, make) BOOST_PROTO_UNARY_OP_RESULT(~, proto::tag::complement, make) BOOST_PROTO_UNARY_OP_RESULT(&, proto::tag::address_of, make) BOOST_PROTO_UNARY_OP_RESULT(!, proto::tag::logical_not, make) BOOST_PROTO_UNARY_OP_RESULT(++, proto::tag::pre_inc, make_mutable) BOOST_PROTO_UNARY_OP_RESULT(--, proto::tag::pre_dec, make_mutable) BOOST_PROTO_BINARY_OP_RESULT(<<, proto::tag::shift_left, make_mutable, make) BOOST_PROTO_BINARY_OP_RESULT(>>, proto::tag::shift_right, make_mutable, make) BOOST_PROTO_BINARY_OP_RESULT(*, proto::tag::multiplies, make, make) BOOST_PROTO_BINARY_OP_RESULT(/, proto::tag::divides, make, make) BOOST_PROTO_BINARY_OP_RESULT(%, proto::tag::modulus, make, make) BOOST_PROTO_BINARY_OP_RESULT(+, proto::tag::plus, make, make) BOOST_PROTO_BINARY_OP_RESULT(-, proto::tag::minus, make, make) BOOST_PROTO_BINARY_OP_RESULT(<, proto::tag::less, make, make) BOOST_PROTO_BINARY_OP_RESULT(>, proto::tag::greater, make, make) BOOST_PROTO_BINARY_OP_RESULT(<=, proto::tag::less_equal, make, make) BOOST_PROTO_BINARY_OP_RESULT(>=, proto::tag::greater_equal, make, make) BOOST_PROTO_BINARY_OP_RESULT(==, proto::tag::equal_to, make, make) BOOST_PROTO_BINARY_OP_RESULT(!=, proto::tag::not_equal_to, make, make) BOOST_PROTO_BINARY_OP_RESULT(||, proto::tag::logical_or, make, make) BOOST_PROTO_BINARY_OP_RESULT(&&, proto::tag::logical_and, make, make) BOOST_PROTO_BINARY_OP_RESULT(&, proto::tag::bitwise_and, make, make) BOOST_PROTO_BINARY_OP_RESULT(|, proto::tag::bitwise_or, make, make) BOOST_PROTO_BINARY_OP_RESULT(^, proto::tag::bitwise_xor, make, make) BOOST_PROTO_BINARY_OP_RESULT(=, proto::tag::assign, make_mutable, make) BOOST_PROTO_BINARY_OP_RESULT(<<=, proto::tag::shift_left_assign, make_mutable, make) BOOST_PROTO_BINARY_OP_RESULT(>>=, proto::tag::shift_right_assign, make_mutable, make) BOOST_PROTO_BINARY_OP_RESULT(*=, proto::tag::multiplies_assign, make_mutable, make) BOOST_PROTO_BINARY_OP_RESULT(/=, proto::tag::divides_assign, make_mutable, make) BOOST_PROTO_BINARY_OP_RESULT(%=, proto::tag::modulus_assign, make_mutable, make) BOOST_PROTO_BINARY_OP_RESULT(+=, proto::tag::plus_assign, make_mutable, make) BOOST_PROTO_BINARY_OP_RESULT(-=, proto::tag::minus_assign, make_mutable, make) BOOST_PROTO_BINARY_OP_RESULT(&=, proto::tag::bitwise_and_assign, make_mutable, make) BOOST_PROTO_BINARY_OP_RESULT(|=, proto::tag::bitwise_or_assign, make_mutable, make) BOOST_PROTO_BINARY_OP_RESULT(^=, proto::tag::bitwise_xor_assign, make_mutable, make) #undef BOOST_PROTO_UNARY_OP_RESULT #undef BOOST_PROTO_BINARY_OP_RESULT /// INTERNAL ONLY template<typename Expr, typename Context> struct is_member_function_eval { typedef typename proto::result_of::child_c<Expr, 1>::type e1; typedef typename proto::result_of::eval<UNREF(e1), Context>::type r1; typedef typename remove_const<typename remove_reference<r1>::type>::type uncvref_r1; typedef typename is_member_function_pointer<uncvref_r1>::type type; BOOST_STATIC_CONSTANT(bool, value = type::value); }; /// INTERNAL ONLY template<typename Expr, typename Context, bool IsMemFunCall> struct memfun_eval { private: typedef typename result_of::child_c<Expr, 0>::type e0; typedef typename result_of::child_c<Expr, 1>::type e1; typedef typename proto::result_of::eval<UNREF(e0), Context>::type r0; typedef typename proto::result_of::eval<UNREF(e1), Context>::type r1; public: typedef typename detail::mem_ptr_fun<r0, r1>::result_type result_type; result_type operator ()(Expr &expr, Context &ctx) const { return detail::mem_ptr_fun<r0, r1>()( proto::eval(proto::child_c<0>(expr), ctx) , proto::eval(proto::child_c<1>(expr), ctx) ); } }; /// INTERNAL ONLY template<typename Expr, typename Context> struct memfun_eval<Expr, Context, true> { private: typedef typename result_of::child_c<Expr, 0>::type e0; typedef typename result_of::child_c<Expr, 1>::type e1; typedef typename proto::result_of::eval<UNREF(e0), Context>::type r0; typedef typename proto::result_of::eval<UNREF(e1), Context>::type r1; public: typedef detail::memfun<r0, r1> result_type; result_type const operator ()(Expr &expr, Context &ctx) const { return detail::memfun<r0, r1>( proto::eval(proto::child_c<0>(expr), ctx) , proto::eval(proto::child_c<1>(expr), ctx) ); } }; template<typename Expr, typename Context> struct default_eval<Expr, Context, tag::mem_ptr, 2> : memfun_eval<Expr, Context, is_member_function_eval<Expr, Context>::value> {}; template<typename Expr, typename Context> struct default_eval<Expr, Context, proto::tag::terminal, 0> { typedef typename proto::result_of::value<Expr &>::type result_type; result_type operator ()(Expr &expr, Context &) const { return proto::value(expr); } }; // Handle post-increment specially. template<typename Expr, typename Context> struct default_eval<Expr, Context, proto::tag::post_inc, 1> { private: typedef typename proto::result_of::child_c<Expr, 0>::type e0; typedef typename proto::result_of::eval<UNREF(e0), Context>::type r0; public: BOOST_PROTO_DECLTYPE_(proto::detail::make_mutable<r0>() ++, result_type) result_type operator ()(Expr &expr, Context &ctx) const { return proto::eval(proto::child_c<0>(expr), ctx) ++; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?