Boost logo

Boost-Commit :

From: ockham_at_[hidden]
Date: 2008-06-16 10:18:27


Author: bernhard.reiter
Date: 2008-06-16 10:18:27 EDT (Mon, 16 Jun 2008)
New Revision: 46424
URL: http://svn.boost.org/trac/boost/changeset/46424

Log:
Add binary predicate version of equal.
Text files modified:
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/general.hpp | 29 ++++++++++++++++++++++++++++-
   1 files changed, 28 insertions(+), 1 deletions(-)

Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/general.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/general.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/algorithm/cursor/general.hpp 2008-06-16 10:18:27 EDT (Mon, 16 Jun 2008)
@@ -50,6 +50,34 @@
         return true;
 }
 
+/**
+ * @brief Checks two subtrees for element-wise equality.
+ * @param c1 An input cursor.
+ * @param c2 An input cursor.
+ * @param p A binary predicate.
+ * @return A boolean true or false.
+ *
+ * Compares the elements of two subtrees using the p parameter.
+ * Returns true if all the corresponding elements of the
+ * subtrees are equal; otherwise, it returns false.
+ */
+template <class InCursor1, class InCursor2, class BinPred>
+bool equal(InCursor1 c1, InCursor2 c2, BinPred p)
+{
+ InCursor1 d1 = c1.end();
+ c1.to_begin();
+ c2.to_begin();
+ if (!p(*c1,*c2))
+ return false;
+ do {
+ if (!c1.empty())
+ if (!equal(c1, c2))
+ return false;
+ ++c2;
+ } while (c1++ != d1);
+
+ return true;
+}
 
 /**
  * @brief Calculates the number of elements in a subtree.
@@ -70,7 +98,6 @@
         while (c++ != d);
 }
 
-
 /**
  * @brief Returns the number of elements in a subtree.
  * @param c An input cursor.


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