Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49022 - sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor
From: ockham_at_[hidden]
Date: 2008-09-29 14:36:53


Author: bernhard.reiter
Date: 2008-09-29 14:36:52 EDT (Mon, 29 Sep 2008)
New Revision: 49022
URL: http://svn.boost.org/trac/boost/changeset/49022

Log:
Re-arrange *order algorithms from namespaces to a policy(=template)-based mechanism, part 5.
Text files modified:
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/inorder.hpp | 34 ++++++++++++++--------------------
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/postorder.hpp | 38 ++++++++++++++++----------------------
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/preorder.hpp | 38 ++++++++++++++++----------------------
   3 files changed, 46 insertions(+), 64 deletions(-)

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-09-29 14:36:52 EDT (Mon, 29 Sep 2008)
@@ -24,8 +24,6 @@
 
 struct inorder {};
 
-namespace inorder {
-
 /** \addtogroup traversal */
 /*\@{*/
 
@@ -35,7 +33,7 @@
  * @ingroup traversal
  */
 template <class MultiwayCursor>
-inline void forward(MultiwayCursor& c)
+inline void forward<inorder>(MultiwayCursor& c)
 {
     if (!(++c).empty()) {
         while (!c.to_begin().empty());
@@ -52,7 +50,7 @@
  * @param c MultiwayCursor to be set to its inorder predecessor
  */
 template <class MultiwayCursor>
-inline void back(MultiwayCursor& c)
+inline void back<inorder>(MultiwayCursor& c)
 {
     if (!c.empty()) {
         while (!c.to_end().empty());
@@ -73,7 +71,7 @@
  * position in the subtree.
  */
 template <class Cursor>
-void to_first(Cursor& c)
+void to_first<inorder>(Cursor& c)
 {
     while (!c.empty())
         c.to_begin();
@@ -86,11 +84,9 @@
  * position in the subtree.
  */
 template <class Cursor>
-void to_last(Cursor& c)
+void to_last<inorder>(Cursor& c)
 { }
 
-#include <boost/tree/detail/algorithm/cursor/_order.hpp>
-
 /*\@}*/
 
 #ifndef BOOST_RECURSIVE_ORDER_ALGORITHMS
@@ -104,7 +100,7 @@
  * @endif
  */
 template <class MultiwayCursor, class Op>
-void for_each_recursive(MultiwayCursor s, Op& f)
+void for_each_recursive<inorder>(MultiwayCursor s, Op& f)
 {
     MultiwayCursor t = s.end();
 
@@ -132,20 +128,20 @@
  */
  //[ inorder_for_each
 template <class MultiwayCursor, class Op>
-Op for_each(MultiwayCursor s, Op f)
+Op for_each<inorder>(MultiwayCursor s, Op f)
 //]
 {
     MultiwayCursor t = s.end();
 
     for (s.to_begin(); s!=t; ++s) {
         if (!s.empty())
- for_each_recursive(s, f);
+ for_each_recursive<inorder>(s, f);
         f(*s);
     }
     
     // Multiway cursor
     if (!t.empty())
- for_each_recursive(t, f);
+ for_each_recursive<inorder>(t, f);
     return f;
 }
 
@@ -158,7 +154,7 @@
  * @result A cursor past t's inorder end, after the copying operation.
  */
 template <class InCursor, class OutCursor>
-OutCursor copy (InCursor s, OutCursor t)
+OutCursor copy<inorder>(InCursor s, OutCursor t)
 {
     InCursor r = s.end();
 
@@ -167,13 +163,13 @@
     
     for (; s != r; ++s, ++t) {
         if (!s.empty())
- copy(s, t);
+ copy<inorder>(s, t);
         *t=*s;
     }
     
     // Multiway cursor
     if (!r.empty())
- copy(r, t);
+ copy<inorder>(r, t);
     return t;
 }
 
@@ -191,7 +187,7 @@
  * op must not change its argument.
  */
 template <class InCursor, class OutCursor, class Op>
-OutCursor transform (InCursor s, OutCursor t, Op op)
+OutCursor transform<inorder>(InCursor s, OutCursor t, Op op)
 {
     InCursor r = s.end();
 
@@ -200,13 +196,13 @@
     
     for (; s != r; ++s, ++t) {
         if (!s.empty())
- transform(s, t, op);
+ transform<inorder>(s, t, op);
         *t=op(*s);
     }
 
     // Multiway cursor
     if (!r.empty())
- transform(r, t, op);
+ transform<inorder>(r, t, op);
     return t;
 }
 
@@ -308,8 +304,6 @@
 // consisting of cursors calculated by calling lower_bound and upper_bound.
 // This might be a bit more subtle for non-binary multiway trees.
 
-} // namespace inorder
-
 } // namespace tree
 } // namespace boost
 

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-09-29 14:36:52 EDT (Mon, 29 Sep 2008)
@@ -17,8 +17,6 @@
 #include <boost/tree/root_tracking_cursor.hpp>
 #include <boost/tree/ascending_cursor.hpp>
 
-namespace postorder {
-
 namespace boost {
 namespace tree {
 
@@ -32,7 +30,7 @@
  * @param c Cursor to be set to its postorder successor
  */
 template <class Cursor>
-inline void forward(Cursor& c)
+inline void forward<postorder>(Cursor& c)
 {
     c.to_parent();
 
@@ -61,7 +59,7 @@
  * @param c Cursor to be set to its postorder predecessor
  */
 template <class Cursor>
-inline void back(Cursor& c)
+inline void back<postorder>(Cursor& c)
 {
     if (c.is_root()) { // Root?
         c.to_begin();
@@ -96,7 +94,7 @@
  * position in the subtree.
  */
 template <class Cursor>
-void to_first(Cursor& c)
+void to_first<postorder>(Cursor& c)
 {
     while (true)
         if (!c.empty())
@@ -116,11 +114,9 @@
  * position in the subtree.
  */
 template <class Cursor>
-void to_last(Cursor& c)
+void to_last<postorder>(Cursor& c)
 { }
 
-#include <boost/tree/detail/algorithm/cursor/_order.hpp>
-
 /*\@}*/
 
 #ifndef BOOST_RECURSIVE_ORDER_ALGORITHMS
@@ -134,16 +130,16 @@
  * @endif
  */
 template <class Cursor, class Op>
-void for_each_recursive(Cursor s, Op& f)
+void for_each_recursive<postorder>(Cursor s, Op& f)
 {
     Cursor t = s;
     for (s.to_begin(); s != t.end(); ++s)
         if (!s.empty())
- for_each_recursive(s, f);
+ for_each_recursive<postorder>(s, f);
 
     // Multiway cursor
     if (!s.empty())
- for_each_recursive(s, f);
+ for_each_recursive<postorder>(s, f);
 
     f(*t.to_begin());
 }
@@ -160,17 +156,17 @@
  */
 //[ postorder_for_each
 template <class Cursor, class Op>
-Op for_each(Cursor s, Op f)
+Op for_each<postorder>(Cursor s, Op f)
 //]
 {
     Cursor t = s;
     for (s.to_begin(); s != t.end(); ++s)
         if (!s.empty())
- for_each_recursive(s, f);
+ for_each_recursive<postorder>(s, f);
 
     // Multiway cursor
     if (!s.empty())
- for_each_recursive(s, f);
+ for_each_recursive<postorder>(s, f);
 
     f(*t.to_begin());
 
@@ -186,7 +182,7 @@
  * @result A cursor past t's postorder end, after the copying operation.
  */
 template <class InCursor, class OutCursor>
-OutCursor copy (InCursor s, OutCursor t)
+OutCursor copy<postorder>(InCursor s, OutCursor t)
 {
     InCursor r = s;
     s.to_begin();
@@ -194,14 +190,14 @@
     
     for (; s != r.end(); ++s, ++t) {
         if (!s.empty())
- copy(s, t);
+ copy<postorder>(s, t);
 // else
 // *t = *s;
     }
     
     // Multiway cursor
     if (!s.empty())
- copy(s, t);
+ copy<postorder>(s, t);
 
     *t = *r.to_begin();
     return t;
@@ -221,7 +217,7 @@
  * op must not change its argument.
  */
 template <class InCursor, class OutCursor, class Op>
-OutCursor transform (InCursor s, OutCursor t, Op op)
+OutCursor transform<postorder>(InCursor s, OutCursor t, Op op)
 {
     InCursor r = s;
     s.to_begin();
@@ -229,11 +225,11 @@
     
     for (; s != r.end(); ++s, ++t)
         if (!s.empty())
- transform(s, t, op);
+ transform<postorder>(s, t, op);
 
     // Multiway cursor
     if (!s.empty())
- transform(s, t, op);
+ transform<postorder>(s, t, op);
     
     *t = op(*r.to_begin());
     return t;
@@ -241,8 +237,6 @@
 
 #endif //BOOST_RECURSIVE_ORDER_ALGORITHMS
 
-} // namespace postorder
-
 } // namespace tree
 } // namespace boost
 

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-09-29 14:36:52 EDT (Mon, 29 Sep 2008)
@@ -17,8 +17,6 @@
 #include <boost/tree/root_tracking_cursor.hpp>
 #include <boost/tree/ascending_cursor.hpp>
 
-namespace preorder {
-
 struct preorder {};
 
 namespace boost {
@@ -32,7 +30,7 @@
  * @param c Cursor to be set to its preorder successor
  */
 template <class Cursor>
-inline void forward(Cursor& c)
+inline void forward<preorder>(Cursor& c)
 {
     // If we have a left child, go there.
     if (!c.empty()) {
@@ -68,7 +66,7 @@
  * @param c Cursor to be set to its preorder predecessor
  */
 template <class Cursor>
-inline void back(Cursor& c)
+inline void back<preorder>(Cursor& c)
 {
     if (!c.is_root()) {
         c.to_parent();
@@ -99,7 +97,7 @@
  * position in the subtree.
  */
 template <class Cursor>
-void to_first(Cursor& c)
+void to_first<preorder>(Cursor& c)
 {
     c.to_begin();
 }
@@ -111,11 +109,9 @@
  * position in the subtree.
  */
 template <class Cursor>
-void to_last(Cursor& c)
+void to_last<preorder>(Cursor& c)
 { }
 
-#include <boost/tree/detail/algorithm/cursor/_order.hpp>
-
 /*\@}*/
 
 #ifndef BOOST_RECURSIVE_ORDER_ALGORITHMS
@@ -129,18 +125,18 @@
  * @endif
  */
 template <class Cursor, class Op>
-void for_each_recursive(Cursor s, Op& f)
+void for_each_recursive<preorder>(Cursor s, Op& f)
 {
     Cursor t = s.end();
     for (s.to_begin(); s != t; ++s) {
         f(*s);
         if (!s.empty())
- for_each_recursive(s, f);
+ for_each_recursive<preorder>(s, f);
     }
     
     // Multiway cursor
     if (!s.empty())
- for_each_recursive(s, f);
+ for_each_recursive<preorder>(s, f);
 }
 
 /**
@@ -155,19 +151,19 @@
  */
 //[ preorder_for_each
 template <class Cursor, class Op>
-Op for_each(Cursor s, Op f)
+Op for_each<preorder>(Cursor s, Op f)
 //]
 {
     Cursor t = s.end();
     for (s.to_begin(); s != t; ++s) {
         f(*s);
         if (!s.empty())
- for_each_recursive(s, f);
+ for_each_recursive<preorder>(s, f);
     }
     
     // Multiway cursor
     if (!s.empty())
- for_each_recursive(s, f);
+ for_each_recursive<preorder>(s, f);
     
     return f;
 }
@@ -181,7 +177,7 @@
  * @result A cursor past t's preorder end, after the copying operation.
  */
 template <class InCursor, class OutCursor>
-OutCursor copy (InCursor s, OutCursor t)
+OutCursor copy<preorder>(InCursor s, OutCursor t)
 {
     InCursor r = s.end();
     s.to_begin();
@@ -190,12 +186,12 @@
     for (; s != r; ++s, ++t) {
         *t = *s;
         if (!s.empty())
- copy(s, t);
+ copy<preorder>(s, t);
     }
 
     // Multiway cursor
     if (!r.empty())
- copy(r, t);
+ copy<preorder>(r, t);
 
     return t;
 }
@@ -214,7 +210,7 @@
  * op must not change its argument.
  */
 template <class InCursor, class OutCursor, class Op>
-OutCursor transform (InCursor s, OutCursor t, Op op)
+OutCursor transform<preorder>(InCursor s, OutCursor t, Op op)
 {
     InCursor r = s.end();
     s.to_begin();
@@ -222,20 +218,18 @@
     for (; s != r; ++s, ++t) {
         *t = op(*s);
         if (!s.empty())
- transform(s, t, op);
+ transform<preorder>(s, t, op);
     }
 
     // Multiway cursor
     if (!s.empty())
- transform(s, t, op);
+ transform<preorder>(s, t, op);
         
     return t;
 }
 
 #endif //BOOST_RECURSIVE_ORDER_ALGORITHMS
 
-} // namespace preorder
-
 } // namespace tree
 } // namespace boost
 


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