|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r60706 - in trunk: boost/proto boost/xpressive libs/proto/doc libs/proto/doc/reference libs/proto/example libs/proto/test
From: eric_at_[hidden]
Date: 2010-03-19 09:23:28
Author: eric_niebler
Date: 2010-03-19 09:23:26 EDT (Fri, 19 Mar 2010)
New Revision: 60706
URL: http://svn.boost.org/trac/boost/changeset/60706
Log:
try again to get proto assignment overloads right
Text files modified:
trunk/boost/proto/extends.hpp | 87 ++++++++++++++++++----
trunk/boost/proto/literal.hpp | 2
trunk/boost/xpressive/regex_primitives.hpp | 2
trunk/libs/proto/doc/front_end.qbk | 4
trunk/libs/proto/doc/reference/extends.xml | 155 ++++++++++++++++++++++++++++-----------
trunk/libs/proto/example/calc2.cpp | 2
trunk/libs/proto/example/calc3.cpp | 2
trunk/libs/proto/test/matches.cpp | 71 +++++++----------
8 files changed, 218 insertions(+), 107 deletions(-)
Modified: trunk/boost/proto/extends.hpp
==============================================================================
--- trunk/boost/proto/extends.hpp (original)
+++ trunk/boost/proto/extends.hpp 2010-03-19 09:23:26 EDT (Fri, 19 Mar 2010)
@@ -10,6 +10,7 @@
#define BOOST_PROTO_EXTENDS_HPP_EAN_11_1_2006
#include <cstddef> // for offsetof
+#include <boost/preprocessor/facilities/empty.hpp>
#include <boost/preprocessor/tuple/elem.hpp>
#include <boost/preprocessor/control/if.hpp>
#include <boost/preprocessor/arithmetic/inc.hpp>
@@ -30,6 +31,12 @@
#include <boost/proto/traits.hpp>
#include <boost/proto/generate.hpp>
+#ifdef _MSC_VER
+#define BOOST_PROTO_DISABLE_MSVC_C4522 __pragma(warning(disable: 4522))
+#else
+#define BOOST_PROTO_DISABLE_MSVC_C4522
+#endif
+
namespace boost { namespace proto
{
#ifdef __GNUC__
@@ -187,9 +194,40 @@
typedef void proto_is_aggregate_; \
/**< INTERNAL ONLY */
- #define BOOST_PROTO_EXTENDS_ASSIGN_DEFAULT(This) \
- typename boost::result_of< \
- proto_domain( \
+ #define BOOST_PROTO_EXTENDS_COPY_ASSIGN_(This, Typename) \
+ BOOST_PROTO_DISABLE_MSVC_C4522 \
+ Typename() boost::result_of< \
+ Typename() This::proto_domain( \
+ boost::proto::expr< \
+ boost::proto::tag::assign \
+ , boost::proto::list2< \
+ This & \
+ , This & \
+ > \
+ , 2 \
+ > \
+ ) \
+ >::type const \
+ operator =(This &a) \
+ { \
+ typedef boost::proto::expr< \
+ boost::proto::tag::assign \
+ , boost::proto::list2< \
+ This & \
+ , This & \
+ > \
+ , 2 \
+ > that_type; \
+ that_type that = { \
+ *this \
+ , a \
+ }; \
+ return Typename() This::proto_domain()(that); \
+ } \
+ \
+ BOOST_PROTO_DISABLE_MSVC_C4522 \
+ Typename() boost::result_of< \
+ Typename() This::proto_domain( \
boost::proto::expr< \
boost::proto::tag::assign \
, boost::proto::list2< \
@@ -214,7 +252,7 @@
*this \
, a \
}; \
- return proto_domain()(that); \
+ return Typename() This::proto_domain()(that); \
} \
/**/
@@ -282,32 +320,32 @@
} \
/**/
- #define BOOST_PROTO_EXTENDS_ASSIGN_CONST_(This) \
- BOOST_PROTO_EXTENDS_ASSIGN_DEFAULT(This) \
+ #define BOOST_PROTO_EXTENDS_ASSIGN_CONST_() \
BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(1) \
/**/
- #define BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST_(This) \
- BOOST_PROTO_EXTENDS_ASSIGN_DEFAULT(This) \
+ #define BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST_() \
BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(0) \
/**/
- #define BOOST_PROTO_EXTENDS_ASSIGN_(This) \
- BOOST_PROTO_EXTENDS_ASSIGN_DEFAULT(This) \
+ #define BOOST_PROTO_EXTENDS_ASSIGN_() \
BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(0) \
BOOST_PROTO_EXTENDS_ASSIGN_IMPL_(1) \
/**/
#define BOOST_PROTO_EXTENDS_ASSIGN_CONST() \
- BOOST_PROTO_EXTENDS_ASSIGN_CONST_(proto_derived_expr) \
+ BOOST_PROTO_EXTENDS_COPY_ASSIGN_(proto_derived_expr, BOOST_PROTO_TYPENAME) \
+ BOOST_PROTO_EXTENDS_ASSIGN_CONST_() \
/**/
#define BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST() \
- BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST_(proto_derived_expr) \
+ BOOST_PROTO_EXTENDS_COPY_ASSIGN_(proto_derived_expr, BOOST_PROTO_TYPENAME) \
+ BOOST_PROTO_EXTENDS_ASSIGN_NON_CONST_() \
/**/
#define BOOST_PROTO_EXTENDS_ASSIGN() \
- BOOST_PROTO_EXTENDS_ASSIGN_(proto_derived_expr) \
+ BOOST_PROTO_EXTENDS_COPY_ASSIGN_(proto_derived_expr, BOOST_PROTO_TYPENAME) \
+ BOOST_PROTO_EXTENDS_ASSIGN_() \
/**/
/// INTERNAL ONLY
@@ -460,6 +498,21 @@
BOOST_PROTO_EXTENDS_FUNCTION() \
/**/
+ #define BOOST_PROTO_EXTENDS_USING_ASSIGN(Derived) \
+ typedef typename Derived::proto_extends proto_extends; \
+ using proto_extends::operator =; \
+ BOOST_PROTO_EXTENDS_COPY_ASSIGN_(Derived, BOOST_PROTO_TYPENAME) \
+ /**/
+
+ #define BOOST_PROTO_EXTENDS_USING_ASSIGN_NON_DEPENDENT(Derived) \
+ typedef Derived::proto_extends proto_extends; \
+ using proto_extends::operator =; \
+ BOOST_PROTO_EXTENDS_COPY_ASSIGN_(Derived, BOOST_PP_EMPTY) \
+ /**/
+
+ /// INTERNAL ONLY
+ #define BOOST_PROTO_TYPENAME() typename
+
namespace exprns_
{
/// \brief Empty type to be used as a dummy template parameter of
@@ -512,8 +565,9 @@
: proto_expr_(expr_)
{}
+ typedef extends proto_extends;
BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, Domain)
- BOOST_PROTO_EXTENDS_ASSIGN_CONST_(extends)
+ BOOST_PROTO_EXTENDS_ASSIGN_CONST_()
BOOST_PROTO_EXTENDS_SUBSCRIPT_CONST()
// Instead of using BOOST_PROTO_EXTENDS_FUNCTION, which uses
@@ -555,8 +609,9 @@
: proto_expr_(expr_)
{}
+ typedef extends proto_extends;
BOOST_PROTO_BASIC_EXTENDS_(Expr, Derived, Domain)
- BOOST_PROTO_EXTENDS_ASSIGN_(extends)
+ BOOST_PROTO_EXTENDS_ASSIGN_()
BOOST_PROTO_EXTENDS_SUBSCRIPT()
// Instead of using BOOST_PROTO_EXTENDS_FUNCTION, which uses
@@ -603,7 +658,7 @@
BOOST_PP_REPEAT(BOOST_PROTO_MAX_ARITY, BOOST_PROTO_EXTENDS_CHILD, ~)
typedef void proto_is_aggregate_; /**< INTERNAL ONLY */
- BOOST_PROTO_EXTENDS_ASSIGN()
+ BOOST_PROTO_EXTENDS_ASSIGN_()
BOOST_PROTO_EXTENDS_SUBSCRIPT()
BOOST_PROTO_EXTENDS_FUNCTION()
Modified: trunk/boost/proto/literal.hpp
==============================================================================
--- trunk/boost/proto/literal.hpp (original)
+++ trunk/boost/proto/literal.hpp 2010-03-19 09:23:26 EDT (Fri, 19 Mar 2010)
@@ -64,7 +64,7 @@
: base_type(terminal_type::make(u.get()))
{}
- using base_type::operator =;
+ BOOST_PROTO_EXTENDS_USING_ASSIGN(literal)
reference get()
{
Modified: trunk/boost/xpressive/regex_primitives.hpp
==============================================================================
--- trunk/boost/xpressive/regex_primitives.hpp (original)
+++ trunk/boost/xpressive/regex_primitives.hpp 2010-03-19 09:23:26 EDT (Fri, 19 Mar 2010)
@@ -566,7 +566,7 @@
return this->proto_base();
}
- using base_type::operator =;
+ BOOST_PROTO_EXTENDS_USING_ASSIGN_NON_DEPENDENT(mark_tag)
};
// This macro is used when declaring mark_tags that are global because
Modified: trunk/libs/proto/doc/front_end.qbk
==============================================================================
--- trunk/libs/proto/doc/front_end.qbk (original)
+++ trunk/libs/proto/doc/front_end.qbk 2010-03-19 09:23:26 EDT (Fri, 19 Mar 2010)
@@ -324,7 +324,7 @@
// This is usually needed because by default, the compiler-
// generated assignment operator hides extends<>::operator=
- using base_type::operator =;
+ BOOST_PROTO_EXTENDS_USING_ASSIGN(calculator)
typedef double result_type;
@@ -351,7 +351,7 @@
You might be thinking that this expression extension business is unnecessarily complicated. After all, isn't this why C++ supports inheritance? Why can't [^calculator<Expr>] just inherit from [^Expr] directly? The reason is because [^Expr], which presumably is an instantiation of _expr_, has expression template-building operator overloads that will be incorrect for derived types. They will store `*this` by reference to `proto::expr<>`, effectively slicing off any derived parts. _extends_ gives your derived types operator overloads that don't slice off your additional members.]
-Although not strictly necessary in this case, we bring `extends<>::operator=` into scope with a `using` declaration. This is really only necessary if you want expressions like `_1 = 3` to create a lazily evaluated assignment. _extends_ defines the appropriate `operator=` for you, but the compiler-generated `calculator<>::operator=` will hide it unless you make it available with the `using` declaration.
+Although not strictly necessary in this case, we bring `extends<>::operator=` into scope with the `BOOST_PROTO_EXTENDS_USING_ASSIGN()` macro. This is really only necessary if you want expressions like `_1 = 3` to create a lazily evaluated assignment. _extends_ defines the appropriate `operator=` for you, but the compiler-generated `calculator<>::operator=` will hide it unless you make it available with the macro.
Note that in the implementation of `calculator<>::operator()`, we evaluate the expression with the `calculator_context` we defined earlier. As we saw before, the context is what gives the operators their meaning. In the case of the calculator, the context is also what defines the meaning of the placeholder terminals.
Modified: trunk/libs/proto/doc/reference/extends.xml
==============================================================================
--- trunk/libs/proto/doc/reference/extends.xml (original)
+++ trunk/libs/proto/doc/reference/extends.xml 2010-03-19 09:23:26 EDT (Fri, 19 Mar 2010)
@@ -83,7 +83,7 @@
// Unhide proto::extends::operator=
// (This is only necessary if a lazy assignment operator
// makes sense for your domain-specific language.)
- using base_type::operator=;
+ BOOST_PROTO_EXTENDS_USING_ASSIGN(my_expr)
/*
... domain-specific members go here ...
@@ -96,6 +96,12 @@
<listitem>
<computeroutput><macroname>BOOST_PROTO_EXTENDS</macroname>()</computeroutput>
</listitem>
+ <listitem>
+ <computeroutput><macroname>BOOST_PROTO_EXTENDS_USING_ASSIGN</macroname>()</computeroutput>
+ </listitem>
+ <listitem>
+ <computeroutput><macroname>BOOST_PROTO_EXTENDS_USING_ASSIGN_NON_DEPENDENT</macroname>()</computeroutput>
+ </listitem>
</itemizedlist>
</para>
</description>
@@ -354,6 +360,44 @@
</namespace>
</namespace>
+ <macro name="BOOST_PROTO_EXTENDS" kind="functionlike">
+ <macro-parameter name="Expr"/>
+ <macro-parameter name="Derived"/>
+ <macro-parameter name="Domain"/>
+ <purpose>For creating expression wrappers that add behaviors to a Proto expression template, like
+ <computeroutput><classname alt="boost::proto::extends">proto::extends<></classname></computeroutput>,
+ but while retaining POD-ness of the expression wrapper.</purpose>
+ <description>
+ <para>
+ Equivalent to:
+ <programlisting><macroname>BOOST_PROTO_BASIC_EXTENDS</macroname>(Expr, Derived, Domain)
+<macroname>BOOST_PROTO_EXTENDS_ASSIGN</macroname>()
+<macroname>BOOST_PROTO_EXTENDS_SUBSCRIPT</macroname>()
+<macroname>BOOST_PROTO_EXTENDS_FUNCTION</macroname>()</programlisting>
+ </para>
+ <para>
+ <emphasis role="bold">Example:</emphasis><programlisting>template< class Expr >
+struct my_expr;
+
+struct my_domain
+ : <classname alt="boost::proto::domain">proto::domain</classname>< <classname alt="boost::proto::pod_generator">proto::pod_generator</classname>< my_expr > >
+{};
+
+template< class Expr >
+struct my_expr
+{
+ // OK, this makes my_expr<> a valid Proto expression extension.
+ // my_expr<> has overloaded assignment, subscript,
+ // and function call operators that build expression templates.
+ <macroname>BOOST_PROTO_EXTENDS</macroname>(Expr, my_expr, my_domain)
+};
+
+// OK, my_expr<> is POD, so this is statically initialized:
+my_expr< <classname alt="boost::proto::terminal">proto::terminal</classname><int>::type > const _1 = {{1}};</programlisting>
+ </para>
+ </description>
+ </macro>
+
<macro name="BOOST_PROTO_BASIC_EXTENDS" kind="functionlike">
<macro-parameter name="Expr"/>
<macro-parameter name="Derived"/>
@@ -446,14 +490,17 @@
</description>
</macro>
- <macro name="BOOST_PROTO_EXTENDS_SUBSCRIPT" kind="functionlike">
- <purpose>For adding to an expression extension class an overloaded subscript operator that
- builds an expression template.</purpose>
+ <macro name="BOOST_PROTO_EXTENDS_FUNCTION" kind="functionlike">
+ <purpose>For adding to an expression extension class a set of overloaded function call operators
+ that build expression templates.</purpose>
<description>
<para>
- Use <computeroutput>BOOST_PROTO_EXTENDS_SUBSCRIPT()</computeroutput> after <computeroutput>
+ Use <computeroutput>BOOST_PROTO_EXTENDS_FUNCTION()</computeroutput> after <computeroutput>
<macroname>BOOST_PROTO_BASIC_EXTENDS</macroname>()</computeroutput> to give an expression
- extension class an overloaded subscript operator that builds an expression template.
+ extension class a set of overloaded function call operators that build expression templates.
+ In addition, <computeroutput>BOOST_PROTO_EXTENDS_FUNCTION()</computeroutput> adds a nested
+ <computeroutput>result<></computeroutput> class template that is a metafunction for
+ calculating the return type of the overloaded function call operators.
</para>
<para>
See also:
@@ -465,7 +512,7 @@
<computeroutput><macroname>BOOST_PROTO_EXTENDS_ASSIGN</macroname>()</computeroutput>
</listitem>
<listitem>
- <computeroutput><macroname>BOOST_PROTO_EXTENDS_FUNCTION</macroname>()</computeroutput>
+ <computeroutput><macroname>BOOST_PROTO_EXTENDS_SUBSCRIPT</macroname>()</computeroutput>
</listitem>
<listitem>
<computeroutput><macroname>BOOST_PROTO_EXTENDS</macroname>()</computeroutput>
@@ -475,17 +522,14 @@
</description>
</macro>
- <macro name="BOOST_PROTO_EXTENDS_FUNCTION" kind="functionlike">
- <purpose>For adding to an expression extension class a set of overloaded function call operators
- that build expression templates.</purpose>
+ <macro name="BOOST_PROTO_EXTENDS_SUBSCRIPT" kind="functionlike">
+ <purpose>For adding to an expression extension class an overloaded subscript operator that
+ builds an expression template.</purpose>
<description>
<para>
- Use <computeroutput>BOOST_PROTO_EXTENDS_FUNCTION()</computeroutput> after <computeroutput>
+ Use <computeroutput>BOOST_PROTO_EXTENDS_SUBSCRIPT()</computeroutput> after <computeroutput>
<macroname>BOOST_PROTO_BASIC_EXTENDS</macroname>()</computeroutput> to give an expression
- extension class a set of overloaded function call operators that build expression templates.
- In addition, <computeroutput>BOOST_PROTO_EXTENDS_FUNCTION()</computeroutput> adds a nested
- <computeroutput>result<></computeroutput> class template that is a metafunction for
- calculating the return type of the overloaded function call operators.
+ extension class an overloaded subscript operator that builds an expression template.
</para>
<para>
See also:
@@ -497,7 +541,7 @@
<computeroutput><macroname>BOOST_PROTO_EXTENDS_ASSIGN</macroname>()</computeroutput>
</listitem>
<listitem>
- <computeroutput><macroname>BOOST_PROTO_EXTENDS_SUBSCRIPT</macroname>()</computeroutput>
+ <computeroutput><macroname>BOOST_PROTO_EXTENDS_FUNCTION</macroname>()</computeroutput>
</listitem>
<listitem>
<computeroutput><macroname>BOOST_PROTO_EXTENDS</macroname>()</computeroutput>
@@ -507,40 +551,63 @@
</description>
</macro>
- <macro name="BOOST_PROTO_EXTENDS" kind="functionlike">
- <macro-parameter name="Expr"/>
+ <macro name="BOOST_PROTO_EXTENDS_USING_ASSIGN" kind="functionlike">
<macro-parameter name="Derived"/>
- <macro-parameter name="Domain"/>
- <purpose>For creating expression wrappers that add behaviors to a Proto expression template, like
- <computeroutput><classname alt="boost::proto::extends">proto::extends<></classname></computeroutput>,
- but while retaining POD-ness of the expression wrapper.</purpose>
+ <purpose>For exposing in classes that inherit from
+ <computeroutput><classname alt="boost::proto::extends">proto::extends<></classname></computeroutput>
+ the overloaded assignment operators defined therein.</purpose>
<description>
<para>
- Equivalent to:
- <programlisting><macroname>BOOST_PROTO_BASIC_EXTENDS</macroname>(Expr, Derived, Domain)
-<macroname>BOOST_PROTO_EXTENDS_ASSIGN</macroname>()
-<macroname>BOOST_PROTO_EXTENDS_SUBSCRIPT</macroname>()
-<macroname>BOOST_PROTO_EXTENDS_FUNCTION</macroname>()</programlisting>
+ The standard usage of
+ <computeroutput><classname alt="boost::proto::extends">proto::extends<></classname></computeroutput>
+ is to inherit from it. However, the derived class automatically gets a compiler-generated assignment
+ operator that will hide the ones defined in
+ <computeroutput><classname alt="boost::proto::extends">proto::extends<></classname></computeroutput>.
+ Use <code>BOOST_PROTO_EXTENDS_USING_ASSIGN()</code> in the derived class to unhide the assignment
+ operators defined in
+ <computeroutput><classname alt="boost::proto::extends">proto::extends<></classname></computeroutput>.
</para>
<para>
- <emphasis role="bold">Example:</emphasis><programlisting>template< class Expr >
-struct my_expr;
-
-struct my_domain
- : <classname alt="boost::proto::domain">proto::domain</classname>< <classname alt="boost::proto::pod_generator">proto::pod_generator</classname>< my_expr > >
-{};
-
-template< class Expr >
-struct my_expr
-{
- // OK, this makes my_expr<> a valid Proto expression extension.
- // my_expr<> has overloaded assignment, subscript,
- // and function call operators that build expression templates.
- <macroname>BOOST_PROTO_EXTENDS</macroname>(Expr, my_expr, my_domain)
-};
+ See <computeroutput><classname alt="boost::proto::extends">proto::extends<></classname></computeroutput>
+ for an example that demonstrates usage of <code>BOOST_PROTO_EXTENDS_USING_ASSIGN()</code>.
+ </para>
+ </description>
+ </macro>
-// OK, my_expr<> is POD, so this is statically initialized:
-my_expr< <classname alt="boost::proto::terminal">proto::terminal</classname><int>::type > const _1 = {{1}};</programlisting>
+ <macro name="BOOST_PROTO_EXTENDS_USING_ASSIGN_NON_DEPENDENT" kind="functionlike">
+ <macro-parameter name="Derived"/>
+ <purpose>For exposing in classes that inherit from
+ <computeroutput><classname alt="boost::proto::extends">proto::extends<></classname></computeroutput>
+ the overloaded assignment operators defined therein. Unlike the
+ <computeroutput><macroname>BOOST_PROTO_EXTENDS_USING_ASSIGN</macroname>()</computeroutput> macro,
+ <code>BOOST_PROTO_EXTENDS_USING_ASSIGN_NON_DEPENDENT()</code> is for use in non-dependent
+ contexts.
+ </purpose>
+ <description>
+ <para>
+ The standard usage of
+ <computeroutput><classname alt="boost::proto::extends">proto::extends<></classname></computeroutput>
+ is to define a class template that inherits from it. The derived class template automatically gets a
+ compiler-generated assignment operator that hides the ones defined in
+ <computeroutput><classname alt="boost::proto::extends">proto::extends<></classname></computeroutput>.
+ Using <code>BOOST_PROTO_EXTENDS_USING_ASSIGN()</code> in the derived class solves this problem.
+ </para>
+ <para>
+ However, if the expression extension is an ordinary class and not a class template, the usage of
+ <code>BOOST_PROTO_EXTENDS_USING_ASSIGN()</code> is in a so-called non-dependent context. In plain English,
+ it means it is illegal to use <code>typename</code> in some places where it is required in a class template.
+ In those cases, you should use <code>BOOST_PROTO_EXTENDS_USING_ASSIGN_NON_DEPENDENT()</code> instead.
+ </para>
+ <para>
+ See also:
+ <itemizedlist>
+ <listitem>
+ <computeroutput><classname alt="boost::proto::extends">proto::extends<></classname></computeroutput>
+ </listitem>
+ <listitem>
+ <computeroutput><macroname>BOOST_PROTO_EXTENDS_USING_ASSIGN</macroname>()</computeroutput>
+ </listitem>
+ </itemizedlist>
</para>
</description>
</macro>
Modified: trunk/libs/proto/example/calc2.cpp
==============================================================================
--- trunk/libs/proto/example/calc2.cpp (original)
+++ trunk/libs/proto/example/calc2.cpp 2010-03-19 09:23:26 EDT (Fri, 19 Mar 2010)
@@ -62,7 +62,7 @@
: base_type(expr)
{}
- using base_type::operator =;
+ BOOST_PROTO_EXTENDS_USING_ASSIGN(calculator_expression)
// Override operator () to evaluate the expression
double operator ()() const
Modified: trunk/libs/proto/example/calc3.cpp
==============================================================================
--- trunk/libs/proto/example/calc3.cpp (original)
+++ trunk/libs/proto/example/calc3.cpp 2010-03-19 09:23:26 EDT (Fri, 19 Mar 2010)
@@ -97,7 +97,7 @@
: base_type(expr)
{}
- using base_type::operator =;
+ BOOST_PROTO_EXTENDS_USING_ASSIGN(calculator_expression)
// Override operator () to evaluate the expression
double operator ()() const
Modified: trunk/libs/proto/test/matches.cpp
==============================================================================
--- trunk/libs/proto/test/matches.cpp (original)
+++ trunk/libs/proto/test/matches.cpp 2010-03-19 09:23:26 EDT (Fri, 19 Mar 2010)
@@ -13,24 +13,13 @@
#include <boost/mpl/placeholders.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/proto/core.hpp>
+#include <boost/proto/debug.hpp>
#include <boost/proto/transform/arg.hpp>
#include <boost/test/unit_test.hpp>
using namespace boost;
using namespace proto;
-template<typename Grammar, typename Expr>
-void assert_matches(Expr const &expr)
-{
- BOOST_MPL_ASSERT((matches<Expr, Grammar>));
-}
-
-template<typename Grammar, typename Expr>
-void assert_not_matches(Expr const &expr)
-{
- BOOST_MPL_ASSERT_NOT((matches<Expr, Grammar>));
-}
-
struct int_convertible
{
int_convertible() {}
@@ -119,24 +108,24 @@
assert_matches< terminal<int> >( as_child(1) );
assert_matches< terminal<int> >( as_expr(1) );
- assert_not_matches< terminal<int> >( lit('a') );
- assert_not_matches< terminal<int> >( as_child('a') );
- assert_not_matches< terminal<int> >( as_expr('a') );
+ assert_matches_not< terminal<int> >( lit('a') );
+ assert_matches_not< terminal<int> >( as_child('a') );
+ assert_matches_not< terminal<int> >( as_expr('a') );
assert_matches< terminal<convertible_to<int> > >( lit('a') );
assert_matches< terminal<convertible_to<int> > >( as_child('a') );
assert_matches< terminal<convertible_to<int> > >( as_expr('a') );
- assert_not_matches< terminal<int> >( lit((int_convertible())) );
- assert_not_matches< terminal<int> >( as_child((int_convertible())) );
- assert_not_matches< terminal<int> >( as_expr((int_convertible())) );
+ assert_matches_not< terminal<int> >( lit((int_convertible())) );
+ assert_matches_not< terminal<int> >( as_child((int_convertible())) );
+ assert_matches_not< terminal<int> >( as_expr((int_convertible())) );
assert_matches< terminal<convertible_to<int> > >( lit((int_convertible())) );
assert_matches< terminal<convertible_to<int> > >( as_child((int_convertible())) );
assert_matches< terminal<convertible_to<int> > >( as_expr((int_convertible())) );
assert_matches< if_<is_same<_value, int>() > >( lit(1) );
- assert_not_matches< if_<is_same<_value, int>() > >( lit('a') );
+ assert_matches_not< if_<is_same<_value, int>() > >( lit('a') );
assert_matches<
and_<
@@ -145,7 +134,7 @@
>
>( lit(1) );
- assert_not_matches<
+ assert_matches_not<
and_<
terminal<_>
, if_<is_same<_value, int>() >
@@ -172,7 +161,7 @@
assert_matches< terminal<char [N]> >( as_child("hello") );
assert_matches< terminal<char [N]> >( as_expr("hello") );
- assert_not_matches< if_<is_same<_value, int>()> >( lit("hello") );
+ assert_matches_not< if_<is_same<_value, int>()> >( lit("hello") );
assert_matches< terminal<std::string> >( lit(std::string("hello")) );
assert_matches< terminal<std::string> >( as_child(std::string("hello")) );
@@ -182,13 +171,13 @@
assert_matches< terminal<std::basic_string<_> > >( as_child(std::string("hello")) );
assert_matches< terminal<std::basic_string<_> > >( as_expr(std::string("hello")) );
- assert_not_matches< terminal<std::basic_string<_> > >( lit(1) );
- assert_not_matches< terminal<std::basic_string<_> > >( as_child(1) );
- assert_not_matches< terminal<std::basic_string<_> > >( as_expr(1) );
-
- assert_not_matches< terminal<std::basic_string<_,_,_> > >( lit(1) );
- assert_not_matches< terminal<std::basic_string<_,_,_> > >( as_child(1) );
- assert_not_matches< terminal<std::basic_string<_,_,_> > >( as_expr(1) );
+ assert_matches_not< terminal<std::basic_string<_> > >( lit(1) );
+ assert_matches_not< terminal<std::basic_string<_> > >( as_child(1) );
+ assert_matches_not< terminal<std::basic_string<_> > >( as_expr(1) );
+
+ assert_matches_not< terminal<std::basic_string<_,_,_> > >( lit(1) );
+ assert_matches_not< terminal<std::basic_string<_,_,_> > >( as_child(1) );
+ assert_matches_not< terminal<std::basic_string<_,_,_> > >( as_expr(1) );
#if BOOST_WORKAROUND(__HP_aCC, BOOST_TESTED_AT(61700))
typedef std::string const const_string;
@@ -198,15 +187,15 @@
assert_matches< terminal<std::basic_string<_> const & > >( lit(const_string("hello")) );
assert_matches< terminal<std::basic_string<_> const & > >( as_child(const_string("hello")) );
- assert_not_matches< terminal<std::basic_string<_> const & > >( as_expr(const_string("hello")) );
+ assert_matches_not< terminal<std::basic_string<_> const & > >( as_expr(const_string("hello")) );
assert_matches< terminal< void(&)() > >( lit(a_function) );
assert_matches< terminal< void(&)() > >( as_child(a_function) );
assert_matches< terminal< void(&)() > >( as_expr(a_function) );
- assert_not_matches< terminal< void(*)() > >( lit(a_function) );
- assert_not_matches< terminal< void(*)() > >( as_child(a_function) );
- assert_not_matches< terminal< void(*)() > >( as_expr(a_function) );
+ assert_matches_not< terminal< void(*)() > >( lit(a_function) );
+ assert_matches_not< terminal< void(*)() > >( as_child(a_function) );
+ assert_matches_not< terminal< void(*)() > >( as_expr(a_function) );
assert_matches< terminal< convertible_to<void(*)()> > >( lit(a_function) );
assert_matches< terminal< convertible_to<void(*)()> > >( as_child(a_function) );
@@ -218,7 +207,7 @@
assert_matches< terminal< void(* const &)() > >( lit(&a_function) );
assert_matches< terminal< void(* const &)() > >( as_child(&a_function) );
- assert_not_matches< terminal< void(* const &)() > >( as_expr(&a_function) );
+ assert_matches_not< terminal< void(* const &)() > >( as_expr(&a_function) );
assert_matches<
or_<
@@ -227,7 +216,7 @@
>
>( lit(1) );
- assert_not_matches<
+ assert_matches_not<
or_<
if_<is_same<_value, char>() >
, if_<is_same<_value, int>() >
@@ -235,19 +224,19 @@
>( lit(1u) );
assert_matches< Input >( cin_ >> 1 >> 2 >> 3 );
- assert_not_matches< Output >( cin_ >> 1 >> 2 >> 3 );
+ assert_matches_not< Output >( cin_ >> 1 >> 2 >> 3 );
assert_matches< Output >( cout_ << 1 << 2 << 3 );
- assert_not_matches< Input >( cout_ << 1 << 2 << 3 );
+ assert_matches_not< Input >( cout_ << 1 << 2 << 3 );
assert_matches< function< terminal<int>, vararg< terminal<char> > > >( lit(1)('a','b','c','d') );
- assert_not_matches< function< terminal<int>, vararg< terminal<char> > > >( lit(1)('a','b','c',"d") );
+ assert_matches_not< function< terminal<int>, vararg< terminal<char> > > >( lit(1)('a','b','c',"d") );
assert_matches< Anything >( cout_ << 1 << +lit('a') << lit(1)('a','b','c',"d") );
assert_matches< proto::switch_<MyCases> >( lit(1) >> 'a' );
assert_matches< proto::switch_<MyCases> >( lit(1) + 'a' );
- assert_not_matches< proto::switch_<MyCases> >( lit(1) << 'a' );
+ assert_matches_not< proto::switch_<MyCases> >( lit(1) << 'a' );
number<int, two_complement_c> num;
assert_matches<NumberGrammar>(proto::as_expr(num));
@@ -257,11 +246,11 @@
proto::nullary_expr<my_terminal, int>::type i = {0};
assert_matches<proto::nullary_expr<my_terminal, _> >( i );
- assert_not_matches<proto::terminal<_> >( i );
+ assert_matches_not<proto::terminal<_> >( i );
proto::terminal<int>::type j = {0};
assert_matches<proto::terminal<_> >( j );
- assert_not_matches<proto::nullary_expr<my_terminal, _> >( j );
+ assert_matches_not<proto::nullary_expr<my_terminal, _> >( j );
assert_matches<proto::nullary_expr<_, _> >( i );
}
@@ -269,7 +258,7 @@
// 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_not< proto::or_<> >( lit(1) );
assert_matches< proto::and_<proto::terminal<int> > >( lit(1) );
assert_matches< proto::or_<proto::terminal<int> > >( lit(1) );
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