Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49232 - in trunk: boost/spirit/home/classic/iterator/impl libs/spirit/classic/test
From: daniel_james_at_[hidden]
Date: 2008-10-09 18:15:58


Author: danieljames
Date: 2008-10-09 18:15:57 EDT (Thu, 09 Oct 2008)
New Revision: 49232
URL: http://svn.boost.org/trac/boost/changeset/49232

Log:
position_iterator is a forward iterator, so tag it appropriately. 'operator-' was giving incorrect results when there were windows newlines which can cause all sorts of problems.
Text files modified:
   trunk/boost/spirit/home/classic/iterator/impl/position_iterator.ipp | 3 ++-
   trunk/libs/spirit/classic/test/position_iterator_tests.cpp | 28 ++++++++++++++++++++++++++++
   2 files changed, 30 insertions(+), 1 deletions(-)

Modified: trunk/boost/spirit/home/classic/iterator/impl/position_iterator.ipp
==============================================================================
--- trunk/boost/spirit/home/classic/iterator/impl/position_iterator.ipp (original)
+++ trunk/boost/spirit/home/classic/iterator/impl/position_iterator.ipp 2008-10-09 18:15:57 EDT (Thu, 09 Oct 2008)
@@ -124,7 +124,8 @@
     typedef boost::iterator_adaptor<
         main_iter_t,
         ForwardIterT,
- const_value_type
+ const_value_type,
+ boost::forward_traversal_tag
> type;
 };
 

Modified: trunk/libs/spirit/classic/test/position_iterator_tests.cpp
==============================================================================
--- trunk/libs/spirit/classic/test/position_iterator_tests.cpp (original)
+++ trunk/libs/spirit/classic/test/position_iterator_tests.cpp 2008-10-09 18:15:57 EDT (Thu, 09 Oct 2008)
@@ -12,6 +12,7 @@
 #include <vector>
 #include <string>
 #include <list>
+#include <algorithm>
 #include <boost/config.hpp>
 #include <boost/concept_check.hpp>
 #include <boost/mpl/list.hpp>
@@ -60,6 +61,7 @@
 void CheckBasicFunctionality(void);
 void CheckColumnCounting(void);
 void CheckLineExtraction(void);
+void CheckDistance(void);
 
 void CheckInstantiation(void)
 {
@@ -81,6 +83,7 @@
     CheckBasicFunctionality();
     CheckColumnCounting();
     CheckLineExtraction();
+ CheckDistance();
 
     return boost::report_errors();
 }
@@ -378,6 +381,20 @@
     CheckEmptySequence<iterc_t>();
 }
 
+template <typename IterT>
+void CheckDistance(IterT begin)
+{
+ IterT end;
+
+ std::size_t std_distance = std::distance(begin, end);
+
+ std::size_t manual_count = 0;
+ for(IterT it = begin; it != end; ++it)
+ ++manual_count;
+
+ BOOST_TEST(std_distance == manual_count);
+}
+
 
 ///////////////////////////////////////////////////////////////////////////////
 } /* namespace test_impl */
@@ -432,3 +449,14 @@
 {
     test_impl::CheckLineExtraction();
 }
+
+void CheckDistance(void)
+{
+ const char* b = "\n0123\r\n4567\n89\n\r";
+ typedef const char* iter_t;
+
+ test_impl::CheckDistance(position_iterator<iter_t>(b, b+15, ""));
+ test_impl::CheckDistance(position_iterator2<iter_t>(b, b+15, ""));
+ test_impl::CheckDistance(position_iterator<iter_t, file_position_without_column>(b, b+15, ""));
+ test_impl::CheckDistance(position_iterator2<iter_t, file_position_without_column>(b, b+15, ""));
+}
\ No newline at end of file


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