|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r50266 - in trunk: boost/proto libs/proto/test
From: eric_at_[hidden]
Date: 2008-12-14 00:53:23
Author: eric_niebler
Date: 2008-12-14 00:53:21 EST (Sun, 14 Dec 2008)
New Revision: 50266
URL: http://svn.boost.org/trac/boost/changeset/50266
Log:
allow 0- and 1-argument variants of proto::or_ and proto::and_
Text files modified:
trunk/boost/proto/matches.hpp | 38 ++++++++++++++++++++++++++++++++++++++
trunk/boost/proto/proto_fwd.hpp | 21 ++-------------------
trunk/libs/proto/test/matches.cpp | 9 +++++++++
3 files changed, 49 insertions(+), 19 deletions(-)
Modified: trunk/boost/proto/matches.hpp
==============================================================================
--- trunk/boost/proto/matches.hpp (original)
+++ trunk/boost/proto/matches.hpp 2008-12-14 00:53:21 EST (Sun, 14 Dec 2008)
@@ -89,6 +89,18 @@
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 T, typename U>
struct array_matches
: mpl::false_
@@ -393,6 +405,32 @@
: detail::uncvref<typename when<_, If>::template impl<Expr, int, int>::result_type>::type
{};
+ // handle degenerate cases of proto::or_
+ template<typename Expr>
+ struct matches_<Expr, or_<> >
+ : mpl::false_
+ {
+ typedef not_<_> which;
+ };
+
+ template<typename Expr, typename G0>
+ struct matches_<Expr, or_<G0> >
+ : matches_<Expr, typename G0::proto_base_expr>
+ {
+ typedef G0 which;
+ };
+
+ // handle degenerate cases of proto::and_
+ template<typename Expr>
+ struct matches_<Expr, and_<> >
+ : mpl::true_
+ {};
+
+ template<typename Expr, typename G0>
+ struct matches_<Expr, and_<G0> >
+ : matches_<Expr, typename G0::proto_base_expr>
+ {};
+
// handle proto::not_
template<typename Expr, typename Grammar>
struct matches_<Expr, not_<Grammar> >
Modified: trunk/boost/proto/proto_fwd.hpp
==============================================================================
--- trunk/boost/proto/proto_fwd.hpp (original)
+++ trunk/boost/proto/proto_fwd.hpp 2008-12-14 00:53:21 EST (Sun, 14 Dec 2008)
@@ -16,7 +16,6 @@
#include <boost/version.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/preprocessor/cat.hpp>
-#include <boost/preprocessor/arithmetic/sub.hpp>
#include <boost/preprocessor/punctuation/comma.hpp>
#include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
#include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
@@ -317,26 +316,10 @@
namespace control
{
- template<
- typename Grammar0
- , typename Grammar1
- , BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(
- BOOST_PP_SUB(BOOST_PROTO_MAX_LOGICAL_ARITY,2)
- , typename G
- , void
- )
- >
+ template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_PROTO_MAX_LOGICAL_ARITY, typename G, void)>
struct or_;
- template<
- typename Grammar0
- , typename Grammar1
- , BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(
- BOOST_PP_SUB(BOOST_PROTO_MAX_LOGICAL_ARITY,2)
- , typename G
- , void
- )
- >
+ template<BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_PROTO_MAX_LOGICAL_ARITY, typename G, void)>
struct and_;
template<typename Grammar>
Modified: trunk/libs/proto/test/matches.cpp
==============================================================================
--- trunk/libs/proto/test/matches.cpp (original)
+++ trunk/libs/proto/test/matches.cpp 2008-12-14 00:53:21 EST (Sun, 14 Dec 2008)
@@ -263,6 +263,15 @@
assert_matches<proto::nullary_expr<_, _> >( i );
}
+
+ // check 0 and 1 arg forms or or_ and and_
+ {
+ assert_matches< proto::and_<> >( lit(1) );
+ assert_not_matches< proto::or_<> >( lit(1) );
+
+ assert_matches< proto::and_<proto::terminal<int> > >( lit(1) );
+ assert_matches< proto::or_<proto::terminal<int> > >( lit(1) );
+ }
}
using namespace unit_test;
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