Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53840 - trunk/boost/spirit/home/lex/lexer/lexertl
From: hartmut.kaiser_at_[hidden]
Date: 2009-06-12 21:41:49


Author: hkaiser
Date: 2009-06-12 21:41:49 EDT (Fri, 12 Jun 2009)
New Revision: 53840
URL: http://svn.boost.org/trac/boost/changeset/53840

Log:
Spirit: Added operator safe_bool to lexer token type
Text files modified:
   trunk/boost/spirit/home/lex/lexer/lexertl/token.hpp | 12 ++++++++++--
   1 files changed, 10 insertions(+), 2 deletions(-)

Modified: trunk/boost/spirit/home/lex/lexer/lexertl/token.hpp
==============================================================================
--- trunk/boost/spirit/home/lex/lexer/lexertl/token.hpp (original)
+++ trunk/boost/spirit/home/lex/lexer/lexertl/token.hpp 2009-06-12 21:41:49 EDT (Fri, 12 Jun 2009)
@@ -11,6 +11,7 @@
 #endif
 
 #include <boost/spirit/home/qi/detail/assign_to.hpp>
+#include <boost/spirit/home/support/safe_bool.hpp>
 #include <boost/spirit/home/support/argument.hpp>
 #include <boost/spirit/home/support/detail/lexer/generator.hpp>
 #include <boost/spirit/home/support/detail/lexer/rules.hpp>
@@ -144,6 +145,13 @@
         std::pair<Iterator, Iterator> matched_;
 #endif
 
+ // operator_bool() is needed for the safe_bool base class
+ operator typename safe_bool<token>::result_type() const
+ {
+ return safe_bool<token>()(
+ 0 != id_ && std::size_t(boost::lexer::npos) != id_);
+ }
+
     protected:
         id_type id_; // token id, 0 if nothing has been matched
     };
@@ -155,7 +163,7 @@
     operator<< (std::basic_ostream<Char, Traits>& os
       , token<Iterator, AttributeTypes, HasState> const& t)
     {
- if (t.id()) {
+ if (t) {
             Iterator end = t.matched_.second;
             for (Iterator it = t.matched_.first; it != end; ++it)
                 os << *it;
@@ -326,7 +334,7 @@
     inline bool
     token_is_valid(token<Iterator, AttributeTypes, HasState> const& t)
     {
- return 0 != t.id() && std::size_t(boost::lexer::npos) != t.id();
+ return t ? true : false;
     }
 
     ///////////////////////////////////////////////////////////////////////////


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