Boost logo

Boost-Commit :

From: philgarofalo_at_[hidden]
Date: 2007-12-25 18:22:22


Author: pgarofalo
Date: 2007-12-25 18:22:22 EST (Tue, 25 Dec 2007)
New Revision: 42303
URL: http://svn.boost.org/trac/boost/changeset/42303

Log:
Consolidated the min_element_if and max_element_if functions into the minmaxif.hpp header file.
Added:
   sandbox/boost/sequence_algo/minmaxif.hpp (contents, props changed)
Text files modified:
   sandbox/boost/sequence_algo/combinatorial.hpp | 83 +--------------------------------------
   1 files changed, 4 insertions(+), 79 deletions(-)

Modified: sandbox/boost/sequence_algo/combinatorial.hpp
==============================================================================
--- sandbox/boost/sequence_algo/combinatorial.hpp (original)
+++ sandbox/boost/sequence_algo/combinatorial.hpp 2007-12-25 18:22:22 EST (Tue, 25 Dec 2007)
@@ -1,4 +1,4 @@
-// combinatorial.h header file - r-permutation and r-combination algorithms ---//
+// combinatorial.hpp header file - r-permutation and r-combination algorithms ---//
 
 // Copyright © Philip F. Garofalo 2008. All rights reserved.
 // Permission to copy, use, modify, sell and distribute this software
@@ -9,6 +9,8 @@
 // See http://www.boost.org for updates, documentation, and revision
 // history.
 
+// $log$
+//
 // Jun 20 2002 Removed TABs and put in std:: when needed [Herve Bronnimann]
 // Also replaced all iter_swap(i,j) by swap(*i,*j)
 //
@@ -47,84 +49,7 @@
 #include <string>
 #include <boost/utility.hpp> // next()
 #include <algorithm.hpp> // is_sorted()
-#include <minmax.hpp> // formerly contained min/max_element_if()
-
-/* PROPOSED STANDARD EXTENSIONS:
- *
- * min_element_if(first, last, predicate)
- * Effect: returns the smallest element of the subsequence of [first,last)
- * satisfying the predicate (or last if none)
- *
- * min_element_if(first, last, comp, predicate)
- * Effect: returns the smallest element, for the order comp, of the subsequence
- * of [first,last) satisfying the predicate (or last if none)
- *
- * max_element_if(first, last, predicate)
- * Effect: returns the largest element of the subsequence of [first,last)
- * satisfying the predicate (or last if none)
- *
- * max_element_if(first, last, comp, predicate)
- * Effect: returns the largest element, for the order comp, of the subsequence
- * of [first,last) satisfying the predicate (or last if none)
- */
-
- template <class ForwardIter, class UnaryPredicate>
- ForwardIter
- min_element_if(ForwardIter first, ForwardIter last, UnaryPredicate cond)
- {
- while (first != last && !cond(*first))
- ++first;
- if (first == last) return last;
- ForwardIter min_result = first;
- while (++first != last)
- if (cond(*first) && *first < *min_result)
- min_result = first;
- return min_result;
- } // min_element_if
-
- template <class ForwardIter, class BinaryPredicate, class UnaryPredicate>
- ForwardIter
- min_element_if(ForwardIter first, ForwardIter last,
- BinaryPredicate comp, UnaryPredicate cond)
- {
- while (first != last && !cond(*first))
- ++first;
- if (first == last) return last;
- ForwardIter min_result = first;
- while (++first != last)
- if (cond(*first) && comp(*first, *min_result))
- min_result = first;
- return min_result;
- } // min_element_if
-
- template <class ForwardIter, class UnaryPredicate>
- ForwardIter
- max_element_if(ForwardIter first, ForwardIter last, UnaryPredicate cond)
- {
- while (first != last && !cond(*first))
- ++first;
- if (first == last) return last;
- ForwardIter max_result = first;
- while (++first != last)
- if (cond(*first) && *max_result < *first)
- max_result = first;
- return max_result;
- } // max_element_if
-
- template <class ForwardIter, class BinaryPredicate, class UnaryPredicate>
- ForwardIter
- max_element_if(ForwardIter first, ForwardIter last,
- BinaryPredicate comp, UnaryPredicate cond)
- {
- while (first != last && !cond(*first))
- ++first;
- if (first == last) return last;
- ForwardIter max_result = first;
- while (++first != last)
- if (cond(*first) && comp(*max_result, *first))
- max_result = first;
- return max_result;
- } // max_element_if
+#include <minmaxif.hpp> // formerly contained min/max_element_if()
 
 
 namespace boost {

Added: sandbox/boost/sequence_algo/minmaxif.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/sequence_algo/minmaxif.hpp 2007-12-25 18:22:22 EST (Tue, 25 Dec 2007)
@@ -0,0 +1,86 @@
+// minmaxif.hpp -- min_ and max_element_if functions. Originally in minmax.hpp
+// (C) Copyright Hervé Brönnimann, Polytechnic University, 2002--2004
+//
+// $log$
+
+#ifndef BOOST_MINMAXIF_HPP
+#define BOOST_MINMAXIF_HPP
+
+/* PROPOSED STANDARD EXTENSIONS:
+ *
+ * min_element_if(first, last, predicate)
+ * Effect: returns the smallest element of the subsequence of [first,last)
+ * satisfying the predicate (or last if none)
+ *
+ * min_element_if(first, last, comp, predicate)
+ * Effect: returns the smallest element, for the order comp, of the subsequence
+ * of [first,last) satisfying the predicate (or last if none)
+ *
+ * max_element_if(first, last, predicate)
+ * Effect: returns the largest element of the subsequence of [first,last)
+ * satisfying the predicate (or last if none)
+ *
+ * max_element_if(first, last, comp, predicate)
+ * Effect: returns the largest element, for the order comp, of the subsequence
+ * of [first,last) satisfying the predicate (or last if none)
+ */
+
+ template <class ForwardIter, class UnaryPredicate>
+ ForwardIter
+ min_element_if(ForwardIter first, ForwardIter last, UnaryPredicate cond)
+ {
+ while (first != last && !cond(*first))
+ ++first;
+ if (first == last) return last;
+ ForwardIter min_result = first;
+ while (++first != last)
+ if (cond(*first) && *first < *min_result)
+ min_result = first;
+ return min_result;
+ } // min_element_if
+
+ template <class ForwardIter, class BinaryPredicate, class UnaryPredicate>
+ ForwardIter
+ min_element_if(ForwardIter first, ForwardIter last,
+ BinaryPredicate comp, UnaryPredicate cond)
+ {
+ while (first != last && !cond(*first))
+ ++first;
+ if (first == last) return last;
+ ForwardIter min_result = first;
+ while (++first != last)
+ if (cond(*first) && comp(*first, *min_result))
+ min_result = first;
+ return min_result;
+ } // min_element_if
+
+ template <class ForwardIter, class UnaryPredicate>
+ ForwardIter
+ max_element_if(ForwardIter first, ForwardIter last, UnaryPredicate cond)
+ {
+ while (first != last && !cond(*first))
+ ++first;
+ if (first == last) return last;
+ ForwardIter max_result = first;
+ while (++first != last)
+ if (cond(*first) && *max_result < *first)
+ max_result = first;
+ return max_result;
+ } // max_element_if
+
+ template <class ForwardIter, class BinaryPredicate, class UnaryPredicate>
+ ForwardIter
+ max_element_if(ForwardIter first, ForwardIter last,
+ BinaryPredicate comp, UnaryPredicate cond)
+ {
+ while (first != last && !cond(*first))
+ ++first;
+ if (first == last) return last;
+ ForwardIter max_result = first;
+ while (++first != last)
+ if (cond(*first) && comp(*max_result, *first))
+ max_result = first;
+ return max_result;
+ } // max_element_if
+
+#endif // BOOST_MINMAXIF_HPP


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