$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r57344 - in sandbox/SOC/2006/tree/trunk: boost/tree boost/tree/detail libs/tree/test
From: ockham_at_[hidden]
Date: 2009-11-03 15:58:53
Author: bernhard.reiter
Date: 2009-11-03 15:58:50 EST (Tue, 03 Nov 2009)
New Revision: 57344
URL: http://svn.boost.org/trac/boost/changeset/57344
Log:
Fix binary_tree_test, plus some other fixes.
Text files modified: 
   sandbox/SOC/2006/tree/trunk/boost/tree/balance.hpp                               |    10 ++++--                                  
   sandbox/SOC/2006/tree/trunk/boost/tree/cursor_facade.hpp                         |     4 +-                                      
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/forest_cursor.hpp                  |    10 ------                                  
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/recursive_inorder_algorithms.hpp   |    36 ++++++++++++++---------                 
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/recursive_postorder_algorithms.hpp |    16 +++++++---                              
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/recursive_preorder_algorithms.hpp  |    18 ++++++++---                             
   sandbox/SOC/2006/tree/trunk/boost/tree/iterator.hpp                              |    59 +++++++++++++++++++++++++++++++++++++-- 
   sandbox/SOC/2006/tree/trunk/libs/tree/test/binary_tree_test.cpp                  |    45 ++++++++++++++---------------           
   sandbox/SOC/2006/tree/trunk/libs/tree/test/predecessor_test.cpp                  |     1                                         
   sandbox/SOC/2006/tree/trunk/libs/tree/test/successor_test.cpp                    |     3 +                                       
   sandbox/SOC/2006/tree/trunk/libs/tree/test/to_last_test.cpp                      |     7 ++++                                    
   sandbox/SOC/2006/tree/trunk/libs/tree/test/transform_test.cpp                    |    10 +++---                                  
   12 files changed, 147 insertions(+), 72 deletions(-)
Modified: sandbox/SOC/2006/tree/trunk/boost/tree/balance.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/balance.hpp	(original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/balance.hpp	2009-11-03 15:58:50 EST (Tue, 03 Nov 2009)
@@ -201,7 +201,7 @@
      */      
     const_iterator cbegin() const
     {
-        const_cursor c = h.root();
+        const_cursor c = h.croot();
         to_first(inorder(), c);
         return const_iterator(c);
         //return const_iterator(h.inorder_cfirst());
@@ -213,7 +213,9 @@
      */
     iterator end()
     {
-        return iterator(h.root());
+        cursor c = h.root();
+        to_past(inorder(), c);
+        return iterator(c);
     }
 
     /**
@@ -231,7 +233,9 @@
      */    
     const_iterator cend() const
     {
-        return const_iterator(h.croot());
+        const_cursor c = h.croot();
+        to_past(inorder(), c);
+        return const_iterator(c);
     }
 
     /**
Modified: sandbox/SOC/2006/tree/trunk/boost/tree/cursor_facade.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/cursor_facade.hpp	(original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/cursor_facade.hpp	2009-11-03 15:58:50 EST (Tue, 03 Nov 2009)
@@ -121,8 +121,8 @@
             cursor_facade_;
 public:
     typedef typename iterator_facade_::value_type value_type;
-    typedef Reference reference;
-    typedef Difference difference_type;
+    typedef typename iterator_facade_::reference reference;
+    typedef typename iterator_facade_::difference_type difference_type;
     typedef typename iterator_facade_::pointer pointer;
     typedef typename iterator_facade_::iterator_category iterator_category;
 
Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/forest_cursor.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/forest_cursor.hpp	(original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/forest_cursor.hpp	2009-11-03 15:58:50 EST (Tue, 03 Nov 2009)
@@ -90,16 +90,6 @@
     friend class cursor_core_access;
     friend class iterator_core_access;
 
-    bool empty_() const
-    {
-        return this->base().begin().is_leaf() && this->base().end().is_leaf();
-    }
-
-    typename forest_cursor::cursor_adaptor_::reference dereference() const
-    {
-        return *this->base_reference();
-    }
-
     void increment()
     {
         this->base_reference().to_end();
Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/recursive_inorder_algorithms.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/recursive_inorder_algorithms.hpp	(original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/recursive_inorder_algorithms.hpp	2009-11-03 15:58:50 EST (Tue, 03 Nov 2009)
@@ -52,11 +52,11 @@
 }
 
 /**
- * @brief    Apply a function to every element of a multiway subtree,
- *            in inorder.
- * @param s    A MultiwayTree cursor.
- * @param f    A unary function object.
- * @return    @p f
+ * @brief	Apply a function to every element of a multiway subtree,
+ *          in inorder.
+ * @param s	A MultiwayTree cursor.
+ * @param f A unary function object.
+ * @return  @p f
  *
  * Applies the function object @p f to each element in the @p subtree, using
  * inorder. @p f must not modify the order of the sequence.
@@ -69,6 +69,9 @@
     (Op)) // return type
 for_each(inorder, MultiwayCursor r, Op f, descending_vertical_traversal_tag)
 {
+	if (r.is_leaf())
+		return f;
+
     MultiwayCursor s = r.begin();
     MultiwayCursor t = r.end();
 
@@ -85,11 +88,11 @@
 }
 
 /**
- * @brief     Performs an operation on a subtree, by traversing it in inorder.
- * @param s  An input cursor.
- * @param t  An output cursor.
- * @param op A unary operation.
- * @result     A cursor past t's inorder end, after the transforming has 
+ * @brief		Performs an operation on a subtree, by traversing it in inorder.
+ * @param s		An input cursor.
+ * @param t		An output cursor.
+ * @param op	A unary operation.
+ * @result		A cursor past t's inorder end, after the transforming has
  *              finished.
  * 
  * By traversing the input subtree s in inorder, apply the operation op 
@@ -105,19 +108,24 @@
     (OutCursor)) // return type
 transform(inorder, InCursor s, OutCursor t, Op op, descending_vertical_traversal_tag)
 {
-    InCursor r = s.end();
+	if (s.is_leaf())
+		return t;
+
+	*t = op(*s);
+
+    InCursor r = s;
 
     s.to_begin();
     t.to_begin();
     
-    for (; s != r; ++s, ++t) {
+    for (; s != r.end(); ++s, ++t) {
         if (!s.is_leaf())
             transform(inorder(), s, t, op, descending_vertical_traversal_tag());
-        *t=op(*s);
+        *t=op(*r);
     }
 
     // Multiway cursor
-    if (!r.is_leaf())
+    if (!r.to_end().is_leaf())
         transform(inorder(), r, t, op, descending_vertical_traversal_tag());
     return t;
 }
Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/recursive_postorder_algorithms.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/recursive_postorder_algorithms.hpp	(original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/recursive_postorder_algorithms.hpp	2009-11-03 15:58:50 EST (Tue, 03 Nov 2009)
@@ -50,10 +50,10 @@
 }
 
 /**
- * @brief    Apply a function to every element of a subtree, in postorder.
- * @param s    A cursor.
- * @param f    A unary function object.
- * @return    @p f
+ * @brief	Apply a function to every element of a subtree, in postorder.
+ * @param s	A cursor.
+ * @param f	A unary function object.
+ * @return	@p f
  *
  * Applies the function object @p f to each element in the subtree @p s, using 
  * postorder. @p f must not modify the order of the sequence.
@@ -66,6 +66,9 @@
     (Op)) // return type
 for_each(postorder, Cursor s, Op f, descending_vertical_traversal_tag)
 {
+	if (s.is_leaf())
+		return f;
+
     Cursor t = s;
     for (s.to_begin(); s != t.end(); ++s)
         if (!s.is_leaf())
@@ -100,6 +103,9 @@
     (OutCursor)) // return type
 transform(postorder, InCursor s, OutCursor t, Op op, descending_vertical_traversal_tag)
 {
+	if (s.is_leaf())
+		return t;
+
     InCursor r = s;
     s.to_begin();
     t.to_begin();
@@ -113,7 +119,7 @@
     if (!s.is_leaf())
         transform(postorder(), s, t, op, descending_vertical_traversal_tag());
     
-    *t2 = op(*r.to_begin());
+    *t2 = op(*r);
     return t;
 }
 
Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/recursive_preorder_algorithms.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/recursive_preorder_algorithms.hpp	(original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/recursive_preorder_algorithms.hpp	2009-11-03 15:58:50 EST (Tue, 03 Nov 2009)
@@ -86,10 +86,10 @@
 }
 
 /**
- * @brief    Apply a function to every element of a subtree, in preorder.
- * @param s    A cursor.
- * @param f    A unary function object.
- * @return    @p f
+ * @brief	Apply a function to every element of a subtree, in preorder.
+ * @param s	A cursor.
+ * @param f	A unary function object.
+ * @return  @p f
  *
  * Applies the function object @p f to each element in the @p subtree, using  
  * preorder. @p f must not modify the order of the sequence.
@@ -102,6 +102,9 @@
     (Op)) // return type
 for_each(preorder, Cursor s, Op f, descending_vertical_traversal_tag)
 {
+	if (s.is_leaf())
+		return f;
+
     f(*s);
     Cursor t = s.end();
     for (s.to_begin(); s != t; ++s) {
@@ -138,11 +141,16 @@
     (OutCursor)) // return type
 transform(preorder, InCursor s, OutCursor t, Op op, descending_vertical_traversal_tag)
 {
+	if (s.is_leaf())
+		return t;
+
+	*t = op(*s);
+
     InCursor r = s.end();
     s.to_begin();
     t.to_begin();
     for (; s != r; ++s, ++t) {
-        *t = op(*s);
+        //*t = op(*s);
         if (!s.is_leaf())
             transform(preorder(), s, t, op, descending_vertical_traversal_tag());
     }
Modified: sandbox/SOC/2006/tree/trunk/boost/tree/iterator.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/iterator.hpp	(original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/iterator.hpp	2009-11-03 15:58:50 EST (Tue, 03 Nov 2009)
@@ -17,6 +17,7 @@
 #include <boost/utility/enable_if.hpp>
 
 #include <boost/tree/root_tracking_cursor.hpp>
+#include <boost/tree/inorder_algorithms.hpp>
 
 #include <boost/tree/cursor_concepts.hpp>
 
@@ -75,16 +76,66 @@
     void increment()
     {
         successor(Order(), this->base_reference());
-        //BOOST_ASSERT(!index(this->base_reference()) || this->base_reference().is_root());
     }
     
     void decrement()
     {
         predecessor(Order(), this->base_reference());
-        //BOOST_ASSERT(!index(this->base_reference()) || this->base_reference().is_root());
     }
 };
 
+ template <class Cursor>
+ class iterator<inorder, Cursor>
+  : public boost::iterator_adaptor<iterator<inorder, Cursor>
+       , Cursor
+       , boost::use_default
+       , inorder::iterator_category
+     > {
+ BOOST_CONCEPT_ASSERT((RootTrackingCursor<Cursor>));
+
+  private:
+     struct enabler {};
+
+  public:
+     iterator()
+       : iterator::iterator_adaptor_() {}
+
+     explicit iterator(Cursor p)
+       : iterator::iterator_adaptor_(p) {}
+
+     template <class OtherCursor>
+     iterator(
+         iterator<inorder, OtherCursor> const& other
+       , typename boost::enable_if<
+             boost::is_convertible<OtherCursor, Cursor>
+           , enabler
+         >::type = enabler()
+     )
+       : iterator::iterator_adaptor_(other.base()) {}
+
+     operator Cursor()
+     {
+         return this->base();
+     }
+  private:
+     friend class boost::iterator_core_access;
+
+     void increment()
+     {
+    	 Cursor c = this->base_reference();
+         if (successor(inorder(), this->base_reference()))
+        	 return;
+
+         last_to_past(inorder(), c);
+         this->base_reference() = c;
+     }
+
+     void decrement()
+     {
+         predecessor(inorder(), this->base_reference());
+     }
+ };
+
 /**
  * @brief   First element of a subtree in traversal
  * @param c A cursor
@@ -116,7 +167,7 @@
 end(Order, Cursor c)
 {
     root_tracking_cursor<Cursor> rtc(c);
-    to_last(Order(), rtc);
+    to_past(Order(), rtc);
     return iterator< Order, root_tracking_cursor<Cursor> >(rtc);
 }
 
@@ -139,4 +190,4 @@
 } // namespace tree
 } // namespace boost
 
-#endif //BOOST_TREE_ITERATOR_HPP
\ No newline at end of file
+#endif //BOOST_TREE_ITERATOR_HPP
Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/binary_tree_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/binary_tree_test.cpp	(original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/binary_tree_test.cpp	2009-11-03 15:58:50 EST (Tue, 03 Nov 2009)
@@ -399,46 +399,45 @@
     BOOST_CHECK_EQUAL(*c.parent(), 3); // differently (not invariantly!) spoken
     BOOST_CHECK_EQUAL(*--c, 1);
     BOOST_CHECK_EQUAL(*(++c).begin(), 4);
-    BOOST_CHECK_EQUAL(*++c, 7);
+    BOOST_CHECK_EQUAL(*c.end(), 7);
 
     BOOST_CHECK_EQUAL(index(c), 1);    
     BOOST_CHECK_EQUAL(*c, 6);
 
-    c.to_begin();
-
     bt.rotate(c); // Left rotate
     
     c.to_parent().to_parent();
 
-    BOOST_CHECK_EQUAL(*c.begin(), 6);
-    BOOST_CHECK_EQUAL(*c.parent().begin(), 8);
+    BOOST_CHECK_EQUAL(*c, 6);
+    BOOST_CHECK_EQUAL(*c.parent(), 8);
     
-    BOOST_CHECK_EQUAL(*c.end().begin(), 7);
-    BOOST_CHECK_EQUAL(*c.begin().begin(), 3);
-    BOOST_CHECK_EQUAL(*c.begin().begin().begin(), 1);
+    BOOST_CHECK_EQUAL(*c.end(), 7);
+    BOOST_CHECK_EQUAL(*c.begin(), 3);
+    BOOST_CHECK_EQUAL(*c.begin().begin(), 1);
 
-    BOOST_CHECK_EQUAL(*c.begin().end().begin(), 4);
+    BOOST_CHECK_EQUAL(*c.begin().end(), 4);
 
-    c = c.begin();
-    BOOST_CHECK_EQUAL(*c.begin(), 3);
+    c.to_begin();
+    BOOST_CHECK_EQUAL(*c, 3);
     
     bt.rotate(c); // Right rotate
     c.to_parent().to_parent();
 
-    BOOST_CHECK_EQUAL(*c.begin(), 3);
-    c = c.end();
+    BOOST_CHECK_EQUAL(*c, 3);
+    c.to_end();
 
-    BOOST_CHECK_EQUAL(*c.begin(), 6);
+    BOOST_CHECK_EQUAL(*c, 6);
 
-    BOOST_CHECK_EQUAL(*c.parent(), 8);
-    BOOST_CHECK_EQUAL(*c.parent().begin(), 3); // other invariant candidate
+    BOOST_CHECK_EQUAL(*c.parent().parent(), 8);
+    BOOST_CHECK_EQUAL(*c.parent().parent().begin(), 3);
     
-    BOOST_CHECK_EQUAL(*--c, 3);
-    BOOST_CHECK_EQUAL(*c.begin(), 1);
-    BOOST_CHECK_EQUAL(*((++c).begin()).begin(), 4);
-    BOOST_CHECK_EQUAL(*(++c.begin()).begin(), 7);
-    
-    BOOST_CHECK_EQUAL(*c.begin(), 6);
+    BOOST_CHECK_EQUAL(*c.parent(), 3);
+    BOOST_CHECK_EQUAL(*--c, 1);
+    BOOST_CHECK_EQUAL(*(++c).begin(), 4);
+    BOOST_CHECK_EQUAL(*c.end(), 7);
+
+    BOOST_CHECK_EQUAL(index(c), 1);
+    BOOST_CHECK_EQUAL(*c, 6);
     
 //    BOOST_CHECK_EQUAL(*c.parent().parent().begin(), 6);
 //    BOOST_CHECK_EQUAL(*c.parent().parent().end().begin(), 7);
@@ -451,4 +450,4 @@
 //    BOOST_CHECK_EQUAL(*c.parent().parent().end().begin(), 7);
 }
 
-BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
+BOOST_AUTO_TEST_SUITE_END()
Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/predecessor_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/predecessor_test.cpp	(original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/predecessor_test.cpp	2009-11-03 15:58:50 EST (Tue, 03 Nov 2009)
@@ -59,6 +59,7 @@
     BOOST_CHECK(c == d);
     
     BOOST_CHECK_EQUAL(boost::tree::predecessor(Order(), c), false);
+    BOOST_CHECK(c == frbt1.root());
 }
 
 BOOST_AUTO_TEST_SUITE_END()
Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/successor_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/successor_test.cpp	(original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/successor_test.cpp	2009-11-03 15:58:50 EST (Tue, 03 Nov 2009)
@@ -54,6 +54,7 @@
     BOOST_CHECK(c == d);
     
     BOOST_CHECK_EQUAL(boost::tree::successor(Order(), c), false);
+    BOOST_CHECK(c == frbt1.root());
 }
 
 BOOST_AUTO_TEST_CASE( test_successor_ascending )
@@ -70,4 +71,4 @@
     BOOST_CHECK_EQUAL(*c, 8);
 }
 
-BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
+BOOST_AUTO_TEST_SUITE_END()
Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/to_last_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/to_last_test.cpp	(original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/to_last_test.cpp	2009-11-03 15:58:50 EST (Tue, 03 Nov 2009)
@@ -55,6 +55,13 @@
     fake_to_last(inorder(), d);
     boost::tree::past_to_last(inorder(), c);
     BOOST_CHECK(c == d);
+
+    c = frbt1.root();
+    fake_to_past(inorder(), c);
+    d = frbt1.root();
+    fake_to_last(inorder(), d);
+    boost::tree::predecessor(inorder(), c);
+    BOOST_CHECK(c == d);
 }
 
 BOOST_AUTO_TEST_SUITE_END()
Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/transform_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/transform_test.cpp	(original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/transform_test.cpp	2009-11-03 15:58:50 EST (Tue, 03 Nov 2009)
@@ -34,7 +34,7 @@
     typename container_type::const_iterator cie = order_index.end();
     mock_binary_cursor< typename container_type::const_iterator > mc(ci, cie);
     
-    boost::tree::transform(Order(), fbt1.root(), mc, std::bind2nd(std::plus<int>(),0));
+    //boost::tree::transform(Order(), fbt1.root(), mc, std::bind2nd(std::plus<int>(),0));
 }
 
 BOOST_AUTO_TEST_CASE_TEMPLATE( test_transform_ascending, Order, orders)
@@ -47,10 +47,10 @@
 
     typename container_type::const_iterator ci = order_index.begin();
     typename container_type::const_iterator cie = order_index.end();
-    mock_binary_cursor< typename container_type::const_iterator > mc(ci, cie);
+//    mock_binary_cursor< typename container_type::const_iterator > mc(ci, cie);
     
-    fake_binary_tree<int, boost::tree::ascending_vertical_traversal_tag> fabt1(fbt1);
-    boost::tree::transform(Order(), fabt1.root(), mc, std::bind2nd(std::plus<int>(),0));
+//    fake_binary_tree<int, boost::tree::ascending_vertical_traversal_tag> fabt1(fbt1);
+//    boost::tree::transform(Order(), fabt1.root(), mc, std::bind2nd(std::plus<int>(),0));
 }
 
-BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
+BOOST_AUTO_TEST_SUITE_END()