|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r61547 - in trunk: boost/proto boost/proto/transform libs/proto/doc libs/proto/doc/reference libs/proto/doc/reference/transform
From: eric_at_[hidden]
Date: 2010-04-24 15:50:17
Author: eric_niebler
Date: 2010-04-24 15:50:15 EDT (Sat, 24 Apr 2010)
New Revision: 61547
URL: http://svn.boost.org/trac/boost/changeset/61547
Log:
when using proto::and_ as a transform, apply *all* transforms but only return the result of applying the last
Text files modified:
trunk/boost/proto/matches.hpp | 77 ++++++++++++++++++++++++---------------
trunk/boost/proto/proto_fwd.hpp | 2 +
trunk/boost/proto/transform/arg.hpp | 19 +++++++++
trunk/libs/proto/doc/back_end.qbk | 4 +-
trunk/libs/proto/doc/reference.xml | 5 ++
trunk/libs/proto/doc/reference/matches.xml | 6 +-
trunk/libs/proto/doc/reference/transform/arg.xml | 38 +++++++++++++++++++
trunk/libs/proto/doc/release_notes.qbk | 15 +++++++
8 files changed, 131 insertions(+), 35 deletions(-)
Modified: trunk/boost/proto/matches.hpp
==============================================================================
--- trunk/boost/proto/matches.hpp (original)
+++ trunk/boost/proto/matches.hpp 2010-04-24 15:50:15 EDT (Sat, 24 Apr 2010)
@@ -16,15 +16,17 @@
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/arithmetic/dec.hpp>
#include <boost/preprocessor/arithmetic/sub.hpp>
- #include <boost/preprocessor/repetition/enum.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/preprocessor/facilities/intercept.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
+ #include <boost/preprocessor/repetition/enum.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_shifted.hpp>
+ #include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/repetition/enum_shifted_params.hpp>
#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
#include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
+ #include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/config.hpp>
#include <boost/mpl/logical.hpp>
#include <boost/mpl/eval_if.hpp>
@@ -71,20 +73,8 @@
template<bool B, typename Pred>
struct and_2;
- template<typename And>
- struct last;
-
- template<>
- struct last<proto::and_<> >
- {
- typedef proto::_ type;
- };
-
- template<typename G0>
- struct last<proto::and_<G0> >
- {
- typedef G0 type;
- };
+ template<typename And, typename Expr, typename State, typename Data>
+ struct _and_impl;
template<typename T, typename U>
struct array_matches
@@ -587,6 +577,19 @@
};
}
+ namespace detail
+ {
+ template<typename Expr, typename State, typename Data>
+ struct _and_impl<proto::and_<>, Expr, State, Data>
+ : proto::_::impl<Expr, State, Data>
+ {};
+
+ template<typename G0, typename Expr, typename State, typename Data>
+ struct _and_impl<proto::and_<G0>, Expr, State, Data>
+ : proto::when<proto::_, G0>::template impl<Expr, State, Data>
+ {};
+ }
+
namespace control
{
/// \brief Inverts the set of expressions matched by a grammar. When
@@ -754,15 +757,15 @@
};
/// \brief For matching all of a set of grammars. When used as a
- /// transform, \c and_\<\> applies the transform associated with
- /// the last grammar in the set.
+ /// transform, \c and_\<\> applies the transforms associated with
+ /// the each grammar in the set, and returns the result of the last.
///
/// An expression type \c E matches <tt>and_\<B0,B1,...Bn\></tt> if \c E
/// matches all \c Bx for \c x in <tt>[0,n)</tt>.
///
/// When applying <tt>and_\<B0,B1,...Bn\></tt> as a transform with an
/// expression \c e, state \c s and data \c d, it is
- /// equivalent to <tt>Bn()(e, s, d)</tt>.
+ /// equivalent to <tt>(B0()(e, s, d),B1()(e, s, d),...Bn()(e, s, d))</tt>.
template<BOOST_PP_ENUM_PARAMS(BOOST_PROTO_MAX_LOGICAL_ARITY, typename G)>
struct and_ : transform<and_<BOOST_PP_ENUM_PARAMS(BOOST_PROTO_MAX_LOGICAL_ARITY, G)> >
{
@@ -770,15 +773,8 @@
template<typename Expr, typename State, typename Data>
struct impl
- : detail::last<and_>::type::template impl<Expr, State, Data>
- {
- /// \param e An expression
- /// \param s The current state
- /// \param d A data of arbitrary type
- /// \pre <tt>matches\<Expr,and_\>::::value</tt> is \c true.
- /// \return <tt>which()(e, s, d)</tt>, where <tt>which</tt> is
- /// the last non-void sub-grammar in the <tt>and_\<\></tt>.
- };
+ : detail::_and_impl<and_, Expr, State, Data>
+ {};
};
/// \brief For matching one of a set of alternate grammars, which
@@ -947,10 +943,31 @@
{};
#if N <= BOOST_PROTO_MAX_LOGICAL_ARITY
- template<BOOST_PP_ENUM_PARAMS(N, typename G)>
- struct last<proto::and_<BOOST_PP_ENUM_PARAMS(N, G)> >
+ template<BOOST_PP_ENUM_PARAMS(N, typename G), typename Expr, typename State, typename Data>
+ struct _and_impl<proto::and_<BOOST_PP_ENUM_PARAMS(N, G)>, Expr, State, Data>
+ : proto::transform_impl<Expr, State, Data>
{
- typedef BOOST_PP_CAT(G, BOOST_PP_DEC(N)) type;
+ #define M0(Z, N, DATA) \
+ typedef \
+ typename proto::when<proto::_, BOOST_PP_CAT(G, N)> \
+ ::template impl<Expr, State, Data> \
+ BOOST_PP_CAT(Gimpl, N); \
+ /**/
+ BOOST_PP_REPEAT(N, M0, ~)
+
+ typedef typename BOOST_PP_CAT(Gimpl, BOOST_PP_DEC(N))::result_type result_type;
+
+ result_type operator()(
+ typename _and_impl::expr_param e
+ , typename _and_impl::state_param s
+ , typename _and_impl::data_param d
+ ) const
+ {
+ // expands to (G0()(e,s,d),G1()(e,s,d),...);
+ return (BOOST_PP_ENUM_BINARY_PARAMS(N, Gimpl, ()(e,s,d) BOOST_PP_INTERCEPT));
+ }
+
+ #undef M0
};
template<bool B, typename Expr, BOOST_PP_ENUM_PARAMS(N, typename G)>
Modified: trunk/boost/proto/proto_fwd.hpp
==============================================================================
--- trunk/boost/proto/proto_fwd.hpp (original)
+++ trunk/boost/proto/proto_fwd.hpp 2010-04-24 15:50:15 EDT (Sat, 24 Apr 2010)
@@ -717,6 +717,8 @@
struct _value;
+ struct _void;
+
template<int I>
struct _child_c;
Modified: trunk/boost/proto/transform/arg.hpp
==============================================================================
--- trunk/boost/proto/transform/arg.hpp (original)
+++ trunk/boost/proto/transform/arg.hpp 2010-04-24 15:50:15 EDT (Sat, 24 Apr 2010)
@@ -210,6 +210,25 @@
};
};
+ /// \brief A PrimitiveTransform that does nothing
+ /// and returns void.
+ struct _void : transform<_void>
+ {
+ template<typename Expr, typename State, typename Data>
+ struct impl : transform_impl<Expr, State, Data>
+ {
+ typedef void result_type;
+
+ /// Does nothing and returns void
+ void operator ()(
+ typename impl::expr_param
+ , typename impl::state_param
+ , typename impl::data_param
+ ) const
+ {}
+ };
+ };
+
/// \brief A unary CallableTransform that wraps its argument
/// in a \c boost::reference_wrapper\<\>.
///
Modified: trunk/libs/proto/doc/back_end.qbk
==============================================================================
--- trunk/libs/proto/doc/back_end.qbk (original)
+++ trunk/libs/proto/doc/back_end.qbk 2010-04-24 15:50:15 EDT (Sat, 24 Apr 2010)
@@ -1248,8 +1248,8 @@
[For the specified set of alternate sub-grammars, find the one that matches
the given expression and apply its associated transform.]]
[[_and_]
- [For the given set of sub-grammars, take the /last/ sub-grammar and apply its
- associated transform.]]
+ [For the given set of sub-grammars, apply all the associated transforms and
+ return the result of the last.]]
[[_not_]
[Return the current expression unmodified.]]
[[_if_]
Modified: trunk/libs/proto/doc/reference.xml
==============================================================================
--- trunk/libs/proto/doc/reference.xml (original)
+++ trunk/libs/proto/doc/reference.xml 2010-04-24 15:50:15 EDT (Sat, 24 Apr 2010)
@@ -52,6 +52,11 @@
</listitem>
<listitem>
<computeroutput>
+ <classname alt="boost::proto::_void">proto::_void</classname>
+ </computeroutput>
+ </listitem>
+ <listitem>
+ <computeroutput>
<classname alt="boost::proto::address_of">proto::address_of</classname>
</computeroutput>
</listitem>
Modified: trunk/libs/proto/doc/reference/matches.xml
==============================================================================
--- trunk/libs/proto/doc/reference/matches.xml (original)
+++ trunk/libs/proto/doc/reference/matches.xml 2010-04-24 15:50:15 EDT (Sat, 24 Apr 2010)
@@ -358,7 +358,7 @@
<inherit><type><classname>proto::transform</classname><and_<G...> ></type></inherit>
<purpose>For matching all of a set of grammars. When used as a transform,
<computeroutput>proto::and_<></computeroutput> applies the transform associated
- with the <emphasis>last</emphasis> grammar in the set.</purpose>
+ with each grammar in the set and returns the result of the last.</purpose>
<description>
<para>
An expression type <computeroutput>E</computeroutput> matches
@@ -371,7 +371,7 @@
<computeroutput>proto::and_<G<subscript>0</subscript>,G<subscript>1</subscript>,...G<subscript>n</subscript>></computeroutput>
as a transform with an expression <computeroutput>e</computeroutput>, state
<computeroutput>s</computeroutput> and data <computeroutput>d</computeroutput>, it is equivalent
- to <computeroutput>G<subscript>n</subscript>()(e, s, d)</computeroutput>.
+ to <computeroutput>(G<subscript>0</subscript>()(e, s, d),G<subscript>1</subscript>()(e, s, d),...G<subscript>n</subscript>()(e, s, d))</computeroutput>.
</para>
<para>
The maximun number of template arguments <computeroutput>proto::and_<></computeroutput> accepts
@@ -412,7 +412,7 @@
</parameter>
<returns>
<para>
- <computeroutput>G<subscript>n</subscript>()(expr, state, data)</computeroutput>
+ <computeroutput>(G<subscript>0</subscript>()(expr, state, data),G<subscript>1</subscript>()(expr, state, data),...G<subscript>n</subscript>()(expr, state, data))</computeroutput>
</para>
</returns>
</method>
Modified: trunk/libs/proto/doc/reference/transform/arg.xml
==============================================================================
--- trunk/libs/proto/doc/reference/transform/arg.xml (original)
+++ trunk/libs/proto/doc/reference/transform/arg.xml 2010-04-24 15:50:15 EDT (Sat, 24 Apr 2010)
@@ -289,6 +289,44 @@
</struct>
</struct>
+ <struct name="_void">
+ <inherit><classname>proto::transform</classname>< _void ></inherit>
+ <purpose>A <conceptname>PrimitiveTransform</conceptname> that does nothing and returns void. </purpose>
+ <struct name="impl">
+ <template>
+ <template-type-parameter name="Expr"/>
+ <template-type-parameter name="State"/>
+ <template-type-parameter name="Data"/>
+ </template>
+ <inherit><classname>proto::transform_impl</classname>< Expr, State, Data ></inherit>
+ <typedef name="result_type">
+ <type>void</type>
+ </typedef>
+ <method-group name="public member functions">
+ <method name="operator()" cv="const">
+ <type>void</type>
+ <parameter name="">
+ <paramtype>typename impl::expr_param</paramtype>
+ </parameter>
+ <parameter name="">
+ <paramtype>typename impl::state_param</paramtype>
+ </parameter>
+ <parameter name="">
+ <paramtype>typename impl::data_param</paramtype>
+ </parameter>
+ <description>
+ <para>
+ Does nothing.
+ </para>
+ </description>
+ <throws>
+ <simpara>Will not throw.</simpara>
+ </throws>
+ </method>
+ </method-group>
+ </struct>
+ </struct>
+
<struct name="_byref">
<inherit><classname>proto::callable</classname></inherit>
<purpose>A unary callable <conceptname>PolymorphicFunctionObject</conceptname> that wraps its argument
Modified: trunk/libs/proto/doc/release_notes.qbk
==============================================================================
--- trunk/libs/proto/doc/release_notes.qbk (original)
+++ trunk/libs/proto/doc/release_notes.qbk 2010-04-24 15:50:15 EDT (Sat, 24 Apr 2010)
@@ -8,6 +8,21 @@
[section:release_notes Appendix A: Release Notes]
[/=================]
+[heading Boost 1.44]
+[/=================]
+
+In Boost 1.44, the behavior of _and_ as a transform changed. Previously, it only
+applied the transform associated with the last grammar in the set. Now, it applies
+all the transforms but only returns the result of the last. That makes it behave
+like C++'s comma operator. For example, a grammar such as:
+
+ proto::and_< G0, G1, G2 >
+
+when evaluated with an expression `e` now behaves like this:
+
+ (G0()(e), G1()(e), G2()(e))
+
+[/=================]
[heading Boost 1.43]
[/=================]
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