Boost logo

Boost-Commit :

From: ockham_at_[hidden]
Date: 2008-07-10 12:16:30


Author: bernhard.reiter
Date: 2008-07-10 12:16:29 EDT (Thu, 10 Jul 2008)
New Revision: 47294
URL: http://svn.boost.org/trac/boost/changeset/47294

Log:
Provide two argument versions of *order::next() and prior()
(Plus some cosmetic fix re cursor_adaptor)
Text files modified:
   sandbox/SOC/2006/tree/trunk/boost/tree/cursor_adaptor.hpp | 24 +++++++-----------------
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/inorder.hpp | 14 ++++++++++----
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/postorder.hpp | 14 ++++++++++----
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/preorder.hpp | 14 ++++++++++----
   sandbox/SOC/2006/tree/trunk/libs/tree/test/binary_tree_search_test.cpp | 2 +-
   5 files changed, 38 insertions(+), 30 deletions(-)

Modified: sandbox/SOC/2006/tree/trunk/boost/tree/cursor_adaptor.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/cursor_adaptor.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/cursor_adaptor.hpp 2008-07-10 12:16:29 EDT (Thu, 10 Jul 2008)
@@ -112,14 +112,12 @@
                                                VerticalTraversalOrCategory, Reference, Difference,
                                                Size> cursor_adaptor_;
         
- typedef cursor_adaptor_base<Derived
- , Base
- , Value
- , HorizontalTraversalOrCategory
- , VerticalTraversalOrCategory
- , Reference
- , Difference
- , Size> super_t;
+ typedef typename cursor_adaptor_base<Derived, Base, Value
+ , HorizontalTraversalOrCategory
+ , VerticalTraversalOrCategory
+ , Reference
+ , Difference
+ , Size>::type cursor_facade_;
         
         Base const& base_reference() const
         { return m_cursor; }
@@ -132,14 +130,6 @@
         
         friend class iterator_core_access;
         friend class cursor_core_access;
-
- typedef cursor_facade<Derived
- , typename super_t::value_type
- , typename super_t::iterator_category
- , typename super_t::vertical_traversal
- , typename super_t::reference
- , typename super_t::difference_type
- , typename super_t::size_type> cursor_facade_;
 
 public:
          typedef Base base_type;
@@ -159,7 +149,7 @@
     Base const& base() const
     { return m_cursor; }
     
- typename super_t::reference dereference() const
+ typename cursor_facade_::reference dereference() const
          {
                  return *m_cursor;
          }

Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/inorder.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/inorder.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/inorder.hpp 2008-07-10 12:16:29 EDT (Thu, 10 Jul 2008)
@@ -44,13 +44,16 @@
 /**
  * @brief Inorder successor
  * @param c A cursor
+ * @param n Optional parameter to indicate how many steps to move forward
  * @return Inorder successor of @a c
  * @ingroup traversal
  */
 template <class MultiwayCursor>
-inline MultiwayCursor next(MultiwayCursor c)
+inline MultiwayCursor next(MultiwayCursor c
+ , typename MultiwayCursor::difference_type n = 1)
 {
- forward(c);
+ for (; n!=0; --n)
+ forward(c);
         return c;
 }
 
@@ -77,12 +80,15 @@
 /**
  * @brief Inorder predecessor
  * @param c MultiwayCursor
+ * @param n Optional parameter to indicate how many steps to move back
  * @return Inorder predecessor of @a c
  */
 template <class MultiwayCursor>
-inline MultiwayCursor prior(MultiwayCursor c)
+inline MultiwayCursor prior(MultiwayCursor c
+ , typename MultiwayCursor::difference_type n = 1)
 {
- back(c);
+ for (; n!=0; --n)
+ back(c);
         return c;
 }
 

Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/postorder.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/postorder.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/postorder.hpp 2008-07-10 12:16:29 EDT (Thu, 10 Jul 2008)
@@ -55,12 +55,15 @@
 /**
  * @brief Postorder successor
  * @param c A cursor
+ * @param n Optional parameter to indicate how many steps to move forward
  * @return Postorder successor of @a c
  */
 template <class Cursor>
-inline Cursor next(Cursor c)
+inline Cursor next(Cursor c
+ , typename Cursor::difference_type n = 1)
 {
- forward(c);
+ for (; n!=0; --n)
+ forward(c);
         return c;
 }
 
@@ -101,12 +104,15 @@
 /**
  * @brief Postorder predecessor
  * @param c A cursor
+ * @param n Optional parameter to indicate how many steps to move back
  * @return Postorder predecessor of @a c
  */
 template <class Cursor>
-inline Cursor prior(Cursor c)
+inline Cursor prior(Cursor c
+ , typename Cursor::difference_type n = 1)
 {
- back(c);
+ for (; n!=0; --n)
+ back(c);
         return c;
 }
 

Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/preorder.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/preorder.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/preorder.hpp 2008-07-10 12:16:29 EDT (Thu, 10 Jul 2008)
@@ -62,12 +62,15 @@
 /**
  * @brief Preorder successor
  * @param c A cursor
+ * @param n Optional parameter to indicate how many steps to move forward
  * @return Preorder successor of @a c
  */
 template <class Cursor>
-inline Cursor next(Cursor c)
+inline Cursor next(Cursor c
+ , typename Cursor::difference_type n = 1)
 {
- forward(c);
+ for (; n!=0; --n)
+ forward(c);
         return c;
 }
 
@@ -104,12 +107,15 @@
 /**
  * @brief Preorder predecessor
  * @param c A cursor
+ * @param n Optional parameter to indicate how many steps to move back
  * @return Preorder predecessor of @a c
  */
 template <class Cursor>
-inline Cursor prior(Cursor c)
+inline Cursor prior(Cursor c
+ , typename Cursor::difference_type n = 1)
 {
- back(c);
+ for (; n!=0; --n)
+ back(c);
         return c;
 }
 

Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/binary_tree_search_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/binary_tree_search_test.cpp (original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/binary_tree_search_test.cpp 2008-07-10 12:16:29 EDT (Thu, 10 Jul 2008)
@@ -58,7 +58,7 @@
         BOOST_CHECK(*c == 4);
         BOOST_CHECK(*d == 7);
         BOOST_CHECK(*c.parent() == 4);
- BOOST_CHECK(inorder::next(inorder::next(c)) == d);
+ BOOST_CHECK(inorder::next(c, 2) == d);
         
         *c.to_parent() = 6;
         validate_test_data_tree(test_tree);


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