Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r68576 - in trunk: boost/spirit/home/support/utree libs/spirit/test/support
From: blelbach_at_[hidden]
Date: 2011-01-31 00:32:01


Author: wash
Date: 2011-01-31 00:31:55 EST (Mon, 31 Jan 2011)
New Revision: 68576
URL: http://svn.boost.org/trac/boost/changeset/68576

Log:
Fix for broken utree logical operations.

Text files modified:
   trunk/boost/spirit/home/support/utree/operators.hpp | 36 +++++++++++++++++++++++++++---------
   trunk/libs/spirit/test/support/utree.cpp | 27 ++++++++++++++++++++++++---
   2 files changed, 51 insertions(+), 12 deletions(-)

Modified: trunk/boost/spirit/home/support/utree/operators.hpp
==============================================================================
--- trunk/boost/spirit/home/support/utree/operators.hpp (original)
+++ trunk/boost/spirit/home/support/utree/operators.hpp 2011-01-31 00:31:55 EST (Mon, 31 Jan 2011)
@@ -287,41 +287,59 @@
         // We assume anything except false is true
 
         // binary
- utree operator()(bool a, bool b) const
+ template <typename A, typename B>
+ utree operator()(A const& a, B const& b) const
         {
- return Base::eval(a, b); // for boolean types
+ return dispatch(a, b
+ , boost::is_arithmetic<A>()
+ , boost::is_arithmetic<B>());
         }
 
         // binary
- template <typename A>
- utree operator()(A const& a, bool b) const
+ template <typename A, typename B>
+ utree dispatch(A const& a, B const& b, mpl::true_, mpl::true_) const
+ {
+ return Base::eval(a, b); // for arithmetic types
+ }
+
+ // binary
+ template <typename A, typename B>
+ utree dispatch(A const& a, B const& b, mpl::false_, mpl::true_) const
         {
             return Base::eval(true, b);
         }
 
         // binary
- template <typename B>
- utree operator()(bool a, B const& b) const
+ template <typename A, typename B>
+ utree dispatch(A const& a, B const& b, mpl::true_, mpl::false_) const
         {
             return Base::eval(a, true);
         }
 
         // binary
         template <typename A, typename B>
- utree operator()(A const& a, B const& b) const
+ utree dispatch(A const& a, B const& b, mpl::false_, mpl::false_) const
         {
             return Base::eval(true, true);
         }
+
+ // unary
+ template <typename A>
+ utree operator()(A const& a) const
+ {
+ return dispatch(a, boost::is_arithmetic<A>());
+ }
 
         // unary
- utree operator()(bool a) const
+ template <typename A>
+ utree dispatch(A const& a, mpl::true_) const
         {
             return Base::eval(a);
         }
 
         // unary
         template <typename A>
- utree operator()(A const& a) const
+ utree dispatch(A const& a, mpl::false_) const
         {
             return Base::eval(true);
         }

Modified: trunk/libs/spirit/test/support/utree.cpp
==============================================================================
--- trunk/libs/spirit/test/support/utree.cpp (original)
+++ trunk/libs/spirit/test/support/utree.cpp 2011-01-31 00:31:55 EST (Mon, 31 Jan 2011)
@@ -310,9 +310,30 @@
 
     { // operators
 
- BOOST_TEST((utree(true) && utree(true)) == utree(true));
- BOOST_TEST((utree(true) || utree(false)) == utree(true));
- BOOST_TEST(!utree(true) == utree(false));
+ BOOST_TEST((utree(false) && utree(false)) == utree(false));
+ BOOST_TEST((utree(false) && utree(true)) == utree(false));
+ BOOST_TEST((utree(true) && utree(false)) == utree(false));
+ BOOST_TEST((utree(true) && utree(true)) == utree(true));
+
+ BOOST_TEST((utree(0) && utree(0)) == utree(false));
+ BOOST_TEST((utree(0) && utree(1)) == utree(false));
+ BOOST_TEST((utree(1) && utree(0)) == utree(false));
+ BOOST_TEST((utree(1) && utree(1)) == utree(true));
+
+ BOOST_TEST((utree(false) || utree(false)) == utree(false));
+ BOOST_TEST((utree(false) || utree(true)) == utree(true));
+ BOOST_TEST((utree(true) || utree(false)) == utree(true));
+ BOOST_TEST((utree(true) || utree(true)) == utree(true));
+
+ BOOST_TEST((utree(0) || utree(0)) == utree(false));
+ BOOST_TEST((utree(0) || utree(1)) == utree(true));
+ BOOST_TEST((utree(1) || utree(0)) == utree(true));
+ BOOST_TEST((utree(1) || utree(1)) == utree(true));
+
+ BOOST_TEST(!utree(true) == utree(false));
+ BOOST_TEST(!utree(false) == utree(true));
+ BOOST_TEST(!utree(1) == utree(false));
+ BOOST_TEST(!utree(0) == utree(true));
 
         BOOST_TEST((utree(456) + utree(123)) == utree(456 + 123));
         BOOST_TEST((utree(456) + utree(123.456)) == utree(456 + 123.456));


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