|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r74470 - in trunk/boost/proto: . transform
From: eric_at_[hidden]
Date: 2011-09-19 17:00:33
Author: eric_niebler
Date: 2011-09-19 17:00:32 EDT (Mon, 19 Sep 2011)
New Revision: 74470
URL: http://svn.boost.org/trac/boost/changeset/74470
Log:
use rvalue references to bring down number of operator overloads
Text files modified:
trunk/boost/proto/operators.hpp | 115 ++++++++++++++++++++++++++++++++-------
trunk/boost/proto/transform/impl.hpp | 44 +++++++++++++++
2 files changed, 137 insertions(+), 22 deletions(-)
Modified: trunk/boost/proto/operators.hpp
==============================================================================
--- trunk/boost/proto/operators.hpp (original)
+++ trunk/boost/proto/operators.hpp 2011-09-19 17:00:32 EDT (Mon, 19 Sep 2011)
@@ -10,6 +10,7 @@
#ifndef BOOST_PROTO_OPERATORS_HPP_EAN_04_01_2005
#define BOOST_PROTO_OPERATORS_HPP_EAN_04_01_2005
+#include <boost/config.hpp>
#include <boost/preprocessor/punctuation/comma.hpp>
#include <boost/mpl/logical.hpp>
#include <boost/utility/enable_if.hpp>
@@ -34,14 +35,14 @@
: boost::lazy_enable_if_c<
boost::mpl::and_<
Trait
- , lazy_matches<result_of::make_expr<Tag, basic_default_domain, Arg &>, Grammar>
+ , lazy_matches<result_of::make_expr<Tag, basic_default_domain, Arg>, Grammar>
>::value
- , result_of::make_expr<Tag, Domain, Arg &>
+ , result_of::make_expr<Tag, Domain, Arg>
>
{};
template<typename Domain, typename Trait, typename Tag, typename Arg>
- struct enable_unary<Domain, proto::_, Trait, Tag, Arg>
+ struct enable_unary<Domain, proto::_, Trait, Tag, Arg &>
: boost::lazy_enable_if_c<
Trait::value
, result_of::make_expr<Tag, Domain, Arg &>
@@ -49,13 +50,13 @@
{};
template<typename Trait, typename Tag, typename Arg>
- struct enable_unary<deduce_domain, not_a_grammar, Trait, Tag, Arg>
+ struct enable_unary<deduce_domain, not_a_grammar, Trait, Tag, Arg &>
: enable_unary<
typename domain_of<Arg>::type
, typename domain_of<Arg>::type::proto_grammar
, Trait
, Tag
- , Arg
+ , Arg &
>
{};
@@ -64,14 +65,14 @@
: boost::lazy_enable_if_c<
boost::mpl::and_<
Trait
- , lazy_matches<result_of::make_expr<Tag, basic_default_domain, Left &, Right &>, Grammar>
+ , lazy_matches<result_of::make_expr<Tag, basic_default_domain, Left, Right>, Grammar>
>::value
- , result_of::make_expr<Tag, Domain, Left &, Right &>
+ , result_of::make_expr<Tag, Domain, Left, Right>
>
{};
template<typename Domain, typename Trait, typename Tag, typename Left, typename Right>
- struct enable_binary<Domain, proto::_, Trait, Tag, Left, Right>
+ struct enable_binary<Domain, proto::_, Trait, Tag, Left &, Right &>
: boost::lazy_enable_if_c<
Trait::value
, result_of::make_expr<Tag, Domain, Left &, Right &>
@@ -79,14 +80,14 @@
{};
template<typename Trait, typename Tag, typename Left, typename Right>
- struct enable_binary<deduce_domain, not_a_grammar, Trait, Tag, Left, Right>
+ struct enable_binary<deduce_domain, not_a_grammar, Trait, Tag, Left &, Right &>
: enable_binary<
typename deduce_domain2<Left, Right>::type
, typename deduce_domain2<Left, Right>::type::proto_grammar
, Trait
, Tag
- , Left
- , Right
+ , Left &
+ , Right &
>
{};
@@ -95,6 +96,8 @@
#define BOOST_PROTO_UNARY_OP_IS_POSTFIX_0
#define BOOST_PROTO_UNARY_OP_IS_POSTFIX_1 , int
+#ifdef BOOST_NO_RVALUE_REFERENCES
+
#define BOOST_PROTO_DEFINE_UNARY_OPERATOR(OP, TAG, TRAIT, DOMAIN, POST) \
template<typename Arg> \
typename boost::proto::detail::enable_unary< \
@@ -102,7 +105,7 @@
, DOMAIN::proto_grammar \
, BOOST_PROTO_APPLY_UNARY_(TRAIT, Arg) \
, TAG \
- , Arg \
+ , Arg & \
>::type const \
operator OP(Arg &arg BOOST_PROTO_UNARY_OP_IS_POSTFIX_ ## POST) \
{ \
@@ -115,7 +118,7 @@
, DOMAIN::proto_grammar \
, BOOST_PROTO_APPLY_UNARY_(TRAIT, Arg) \
, TAG \
- , Arg const \
+ , Arg const & \
>::type const \
operator OP(Arg const &arg BOOST_PROTO_UNARY_OP_IS_POSTFIX_ ## POST) \
{ \
@@ -130,8 +133,8 @@
, DOMAIN::proto_grammar \
, BOOST_PROTO_APPLY_BINARY_(TRAIT, Left, Right) \
, TAG \
- , Left \
- , Right \
+ , Left & \
+ , Right & \
>::type const \
operator OP(Left &left, Right &right) \
{ \
@@ -144,8 +147,8 @@
, DOMAIN::proto_grammar \
, BOOST_PROTO_APPLY_BINARY_(TRAIT, Left, Right) \
, TAG \
- , Left \
- , Right const \
+ , Left & \
+ , Right const & \
>::type const \
operator OP(Left &left, Right const &right) \
{ \
@@ -158,8 +161,8 @@
, DOMAIN::proto_grammar \
, BOOST_PROTO_APPLY_BINARY_(TRAIT, Left, Right) \
, TAG \
- , Left const \
- , Right \
+ , Left const & \
+ , Right & \
>::type const \
operator OP(Left const &left, Right &right) \
{ \
@@ -172,8 +175,8 @@
, DOMAIN::proto_grammar \
, BOOST_PROTO_APPLY_BINARY_(TRAIT, Left, Right) \
, TAG \
- , Left const \
- , Right const \
+ , Left const & \
+ , Right const & \
>::type const \
operator OP(Left const &left, Right const &right) \
{ \
@@ -181,6 +184,41 @@
} \
/**/
+#else
+
+#define BOOST_PROTO_DEFINE_UNARY_OPERATOR(OP, TAG, TRAIT, DOMAIN, POST) \
+ template<typename Arg> \
+ typename boost::proto::detail::enable_unary< \
+ DOMAIN \
+ , DOMAIN::proto_grammar \
+ , BOOST_PROTO_APPLY_UNARY_(TRAIT, Arg) \
+ , TAG \
+ , Arg const & \
+ >::type const \
+ operator OP(Arg &&arg BOOST_PROTO_UNARY_OP_IS_POSTFIX_ ## POST) \
+ { \
+ return boost::proto::detail::make_expr_<TAG, DOMAIN, Arg const &>()(arg); \
+ } \
+ /**/
+
+#define BOOST_PROTO_DEFINE_BINARY_OPERATOR(OP, TAG, TRAIT, DOMAIN) \
+ template<typename Left, typename Right> \
+ typename boost::proto::detail::enable_binary< \
+ DOMAIN \
+ , DOMAIN::proto_grammar \
+ , BOOST_PROTO_APPLY_BINARY_(TRAIT, Left, Right) \
+ , TAG \
+ , Left const & \
+ , Right const & \
+ >::type const \
+ operator OP(Left &&left, Right &&right) \
+ { \
+ return boost::proto::detail::make_expr_<TAG, DOMAIN, Left const &, Right const &>()(left, right);\
+ } \
+ /**/
+
+#endif
+
#define BOOST_PROTO_DEFINE_OPERATORS(TRAIT, DOMAIN) \
BOOST_PROTO_DEFINE_UNARY_OPERATOR(+, boost::proto::tag::unary_plus, TRAIT, DOMAIN, 0) \
BOOST_PROTO_DEFINE_UNARY_OPERATOR(-, boost::proto::tag::negate, TRAIT, DOMAIN, 0) \
@@ -230,6 +268,11 @@
: is_expr<T>
{};
+ template<typename T>
+ struct is_extension<T &>
+ : is_expr<T>
+ {};
+
#define BOOST_PROTO_APPLY_UNARY_(TRAIT, ARG) TRAIT<ARG>
#define BOOST_PROTO_APPLY_BINARY_(TRAIT, LEFT, RIGHT) boost::mpl::or_<TRAIT<LEFT>, TRAIT<RIGHT> >
@@ -268,8 +311,13 @@
// can use BOOST_PROTO_DEFINE_OPERATORS to define Proto operator overloads that work
// with their own terminal types.
+#ifdef BOOST_NO_RVALUE_REFERENCES
+
#define BOOST_PROTO_APPLY_UNARY_(TRAIT, ARG) \
- boost::mpl::and_<TRAIT<ARG>, boost::mpl::not_<boost::proto::is_extension<ARG> > > \
+ boost::mpl::and_< \
+ TRAIT<ARG> \
+ , boost::mpl::not_<boost::proto::is_extension<ARG> > \
+ > \
/**/
#define BOOST_PROTO_APPLY_BINARY_(TRAIT, LEFT, RIGHT) \
@@ -284,6 +332,29 @@
> \
/**/
+#else
+
+ #define BOOST_PROTO_APPLY_UNARY_(TRAIT, ARG) \
+ boost::mpl::and_< \
+ TRAIT<BOOST_PROTO_UNCVREF(ARG) > \
+ , boost::mpl::not_<boost::proto::is_extension<ARG> > \
+ > \
+ /**/
+
+ #define BOOST_PROTO_APPLY_BINARY_(TRAIT, LEFT, RIGHT) \
+ boost::mpl::and_< \
+ boost::mpl::or_<TRAIT<BOOST_PROTO_UNCVREF(LEFT) >, TRAIT<BOOST_PROTO_UNCVREF(RIGHT) > > \
+ , boost::mpl::not_< \
+ boost::mpl::or_< \
+ boost::proto::is_extension<LEFT> \
+ , boost::proto::is_extension<RIGHT> \
+ > \
+ > \
+ > \
+ /**/
+
+#endif
+
}}
#endif
Modified: trunk/boost/proto/transform/impl.hpp
==============================================================================
--- trunk/boost/proto/transform/impl.hpp (original)
+++ trunk/boost/proto/transform/impl.hpp 2011-09-19 17:00:32 EDT (Mon, 19 Sep 2011)
@@ -9,10 +9,13 @@
#ifndef BOOST_PROTO_TRANSFORM_IMPL_HPP_EAN_04_03_2008
#define BOOST_PROTO_TRANSFORM_IMPL_HPP_EAN_04_03_2008
+#include <boost/config.hpp>
#include <boost/proto/proto_fwd.hpp>
namespace boost { namespace proto
{
+#ifdef BOOST_NO_RVALUE_REFERENCES
+
/// INTERNAL ONLY
///
#define BOOST_PROTO_TRANSFORM_(PrimitiveTransform, X) \
@@ -65,6 +68,47 @@
} \
/**/
+#else
+
+ /// INTERNAL ONLY
+ ///
+ #define BOOST_PROTO_TRANSFORM_(PrimitiveTransform, X) \
+ BOOST_PROTO_CALLABLE() \
+ typedef X proto_is_transform_; \
+ typedef PrimitiveTransform transform_type; \
+ \
+ template<typename Sig> \
+ struct result \
+ { \
+ typedef typename boost::proto::detail::apply_transform<Sig>::result_type type; \
+ }; \
+ \
+ template<typename Expr> \
+ typename boost::proto::detail::apply_transform<transform_type(Expr const &)>::result_type \
+ operator ()(Expr &&e) const \
+ { \
+ int i = 0; \
+ return boost::proto::detail::apply_transform<transform_type(Expr const &)>()(e, i, i); \
+ } \
+ \
+ template<typename Expr, typename State> \
+ typename boost::proto::detail::apply_transform<transform_type(Expr const &, State const &)>::result_type \
+ operator ()(Expr &&e, State &&s) const \
+ { \
+ int i = 0; \
+ return boost::proto::detail::apply_transform<transform_type(Expr const &, State const &)>()(e, s, i); \
+ } \
+ \
+ template<typename Expr, typename State, typename Data> \
+ typename boost::proto::detail::apply_transform<transform_type(Expr const &, State const &, Data const &)>::result_type \
+ operator ()(Expr &&e, State &&s, Data &&d) const \
+ { \
+ return boost::proto::detail::apply_transform<transform_type(Expr const &, State const &, Data const &)>()(e, s, d); \
+ } \
+ /**/
+
+#endif
+
#define BOOST_PROTO_TRANSFORM(PrimitiveTransform) \
BOOST_PROTO_TRANSFORM_(PrimitiveTransform, void) \
/**/
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk