Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49537 - in sandbox/SOC/2006/tree/trunk: boost/tree boost/tree/detail/algorithm libs/tree/doc/html libs/tree/test
From: ockham_at_[hidden]
Date: 2008-11-02 12:49:33


Author: bernhard.reiter
Date: 2008-11-02 12:49:33 EST (Sun, 02 Nov 2008)
New Revision: 49537
URL: http://svn.boost.org/trac/boost/changeset/49537

Log:
Make copy() call transform (..., identity<...>) to reduce redundancy.
Move algorithm interfaces to algorithm.hpp
Properties modified:
   sandbox/SOC/2006/tree/trunk/libs/tree/doc/html/ (props changed)
Text files modified:
   sandbox/SOC/2006/tree/trunk/boost/tree/algorithm.hpp | 70 ++++++++++++++++++++++++++++++++++
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/inorder.hpp | 26 ------------
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/iterative.hpp | 82 ---------------------------------------
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/postorder.hpp | 28 -------------
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/preorder.hpp | 26 ------------
   sandbox/SOC/2006/tree/trunk/libs/tree/test/cursor_algorithm_test.cpp | 2
   6 files changed, 72 insertions(+), 162 deletions(-)

Modified: sandbox/SOC/2006/tree/trunk/boost/tree/algorithm.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/algorithm.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/algorithm.hpp 2008-11-02 12:49:33 EST (Sun, 02 Nov 2008)
@@ -88,6 +88,76 @@
     return std::distance(cur.parent().begin(), cur);
 }
 
+/**
+ * @brief Apply a function to every element of a subtree,
+ * in the order specified by the first parameter.
+ * @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.
+ * @p f must not modify the order of the sequence.
+ * If @p f has a return value it is ignored.
+ */
+//[ for_each
+template <class Order, class Cursor, class Op>
+Op for_each(Order, Cursor s, Op f)
+//]
+{
+ return for_each(Order(), s, f
+ , typename cursor_vertical_traversal<Cursor>::type());
+}
+
+/**
+ * @brief Performs an operation on a subtree, by traversing it
+ * in the order specified by the first parameter.
+ * @param s An input cursor.
+ * @param t An output cursor.
+ * @param op A unary operation.
+ * @result A cursor past t's preorder end, after the transforming has
+ * finished.
+ *
+ * By traversing the input subtree s, apply the operation op
+ * to each element and write the result to the output subtree t.
+ *
+ * op must not change its argument.
+ */
+template <class Order, class InCursor, class OutCursor, class Op>
+OutCursor transform (Order, InCursor s, OutCursor t, Op op)
+{
+ return transform(Order(), s, t, op
+ , typename cursor_vertical_traversal<InCursor>::type());
+ // What about OutCursor?
+}
+
+template <class T>
+T identity (T const& x)
+{
+ return x;
+}
+
+template <class Order, class InCursor, class OutCursor, class Traversal>
+OutCursor copy(Order, InCursor s, OutCursor t, Traversal tr)
+{
+ return transform(Order(), s, t
+ , identity<typename cursor_value<InCursor>::type>, tr);
+}
+
+/**
+ * @brief Copies the subtree s into t, by traversing s
+ * in the order specified by the first parameter.
+ * @param s An input cursor.
+ * @param t An output cursor.
+ * @result A cursor past t's *order end, after the copying operation.
+ */
+template <class Order, class InCursor, class OutCursor>
+OutCursor copy (Order, InCursor s, OutCursor t)
+{
+ return copy(Order(), s, t
+ , typename cursor_vertical_traversal<InCursor>::type());
+ // What about OutCursor?
+}
+
 } // namespace tree
 } // namespace boost
 

Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/inorder.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/inorder.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/inorder.hpp 2008-11-02 12:49:33 EST (Sun, 02 Nov 2008)
@@ -144,32 +144,6 @@
 }
 
 /**
- * @brief Copies the subtree s into t, by traversing s in inorder.
- * @param s An input cursor.
- * @param t An output cursor.
- * @result A cursor past t's inorder end, after the copying operation.
- */
-template <class InCursor, class OutCursor>
-OutCursor copy(inorder, InCursor s, OutCursor t, forward_traversal_tag)
-{
- InCursor r = s.end();
-
- s.to_begin();
- t.to_begin();
-
- for (; s != r; ++s, ++t) {
- if (!s.empty())
- copy(inorder(), s, t, forward_traversal_tag());
- *t=*s;
- }
-
- // Multiway cursor
- if (!r.empty())
- copy(inorder(), r, t, forward_traversal_tag());
- return t;
-}
-
-/**
  * @brief Performs an operation on a subtree, by traversing it in inorder.
  * @param s An input cursor.
  * @param t An output cursor.

Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/iterative.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/iterative.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/iterative.hpp 2008-11-02 12:49:33 EST (Sun, 02 Nov 2008)
@@ -40,66 +40,6 @@
     return for_each(Order(), root_tracking_cursor<Cursor>(s), f);
 }
 
-/**
- * @brief Apply a function to every element of a subtree,
- * in the order specified by the first parameter.
- * @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.
- * @p f must not modify the order of the sequence.
- * If @p f has a return value it is ignored.
- */
-//[ for_each
-template <class Order, class Cursor, class Op>
-Op for_each(Order, Cursor s, Op f)
-//]
-{
- return for_each(Order(), s, f
- , typename cursor_vertical_traversal<Cursor>::type());
-}
-
-template <class Order, class InCursor, class OutCursor>
-root_tracking_cursor<OutCursor> copy (Order, root_tracking_cursor<InCursor> s
- , root_tracking_cursor<OutCursor> t)
-{
- root_tracking_cursor<InCursor> s2(s);
- to_first(Order(), s);
- to_last(Order(), s2);
- to_first(Order(), t);
- while (s!=s2) {
- *t = *s;
- forward(Order(), s);
- forward(Order(), t);
- }
- return t;
-}
-
-template <class Order, class InCursor, class OutCursor>
-OutCursor copy (Order, InCursor s, OutCursor t, bidirectional_traversal_tag)
-{
- root_tracking_cursor<OutCursor> u
- = copy(Order(), root_tracking_cursor<InCursor>(s)
- , root_tracking_cursor<OutCursor>(t));
- return u.base();
-}
-
-/**
- * @brief Copies the subtree s into t, by traversing s
- * in the order specified by the first parameter.
- * @param s An input cursor.
- * @param t An output cursor.
- * @result A cursor past t's *order end, after the copying operation.
- */
-template <class Order, class InCursor, class OutCursor>
-OutCursor copy (Order, InCursor s, OutCursor t)
-{
- return copy(Order(), s, t
- , typename cursor_vertical_traversal<InCursor>::type());
- // What about OutCursor?
-}
-
 template <class Order, class InCursor, class OutCursor, class Op>
 root_tracking_cursor<OutCursor> transform (Order
                                          , root_tracking_cursor<InCursor> s
@@ -128,27 +68,7 @@
     return u.base();
 }
 
-/**
- * @brief Performs an operation on a subtree, by traversing it
- * in the order specified by the first parameter.
- * @param s An input cursor.
- * @param t An output cursor.
- * @param op A unary operation.
- * @result A cursor past t's preorder end, after the transforming has
- * finished.
- *
- * By traversing the input subtree s, apply the operation op
- * to each element and write the result to the output subtree t.
- *
- * op must not change its argument.
- */
-template <class Order, class InCursor, class OutCursor, class Op>
-OutCursor transform (Order, InCursor s, OutCursor t, Op op)
-{
- return transform(Order(), s, t, op
- , typename cursor_vertical_traversal<InCursor>::type());
- // What about OutCursor?
-}
+
 
 } // namespace tree
 } // namespace boost

Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/postorder.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/postorder.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/postorder.hpp 2008-11-02 12:49:33 EST (Sun, 02 Nov 2008)
@@ -172,34 +172,6 @@
 }
 
 /**
- * @brief Copies the subtree s into t, by traversing s in postorder.
- * @param s An input cursor.
- * @param t An output cursor.
- * @result A cursor past t's postorder end, after the copying operation.
- */
-template <class InCursor, class OutCursor>
-OutCursor copy(postorder, InCursor s, OutCursor t, forward_traversal_tag)
-{
- InCursor r = s;
- s.to_begin();
- t.to_begin();
-
- for (; s != r.end(); ++s, ++t) {
- if (!s.empty())
- copy(postorder(), s, t, forward_traversal_tag());
-// else
-// *t = *s;
- }
-
- // Multiway cursor
- if (!s.empty())
- copy(postorder(), s, t, forward_traversal_tag());
-
- *t = *r.to_begin();
- return t;
-}
-
-/**
  * @brief Performs an operation on a subtree, by traversing it in postorder.
  * @param s An input cursor.
  * @param t An output cursor.

Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/preorder.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/preorder.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/preorder.hpp 2008-11-02 12:49:33 EST (Sun, 02 Nov 2008)
@@ -171,32 +171,6 @@
 //#endif //BOOST_RECURSIVE_ORDER_ALGORITHMS
 
 /**
- * @brief Copies the subtree s into t, by traversing s in preorder.
- * @param s An input cursor.
- * @param t An output cursor.
- * @result A cursor past t's preorder end, after the copying operation.
- */
-template <class InCursor, class OutCursor>
-OutCursor copy(preorder, InCursor s, OutCursor t, forward_traversal_tag)
-{
- InCursor r = s.end();
- s.to_begin();
- t.to_begin();
-
- for (;s != r; ++s, ++t) {
- *t = *s;
- if (!s.empty())
- copy(preorder(), s, t, forward_traversal_tag());
- }
-
- // Multiway cursor
- if (!r.empty())
- copy(preorder(), r, t, forward_traversal_tag());
-
- return t;
-}
-
-/**
  * @brief Performs an operation on a subtree, by traversing it in preorder.
  * @param s An input cursor.
  * @param t An output cursor.

Modified: sandbox/SOC/2006/tree/trunk/libs/tree/test/cursor_algorithm_test.cpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/libs/tree/test/cursor_algorithm_test.cpp (original)
+++ sandbox/SOC/2006/tree/trunk/libs/tree/test/cursor_algorithm_test.cpp 2008-11-02 12:49:33 EST (Sun, 02 Nov 2008)
@@ -48,7 +48,7 @@
 
 typedef boost::mpl::list<preorder,inorder/*,postorder*/> preandinorders; //FIXME
 
-BOOST_AUTO_TEST_CASE_TEMPLATE ( test_copy2, Order, preandinorders )
+BOOST_AUTO_TEST_CASE_TEMPLATE ( test_inserter, Order, preandinorders )
 {
     //boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_messages ) ;
     bt2.clear();


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