Anonymous avatar Anonymous committed f3a75ba

adding CxxUtils::copy_if implementation (from gcc4.4)

Comments (0)

Files changed (2)

+2009-03-11  Sebastien Binet  <binet@farnsworth>
+
+	* tagging CxxUtils-00-00-20
+	* adding CxxUtils::copy_if implementation (from gcc4.4)
+	* A CxxUtils/algorithms.h
+
 2009-03-10  Paolo Calafiura  
 	* Tagging CxxUtils-00-00-19 
 	* src/procmaps.cxx (procmaps::Entry): fix sscanf compilation warning (thanks Wim)

CxxUtils/algorithms.h

+///////////////////////// -*- C++ -*- /////////////////////////////
+// algorithms.h 
+// Header file for CxxUtils::copy_if - copied from gcc4.4
+// Author: S.Binet<binet@cern.ch>
+/////////////////////////////////////////////////////////////////// 
+#ifndef CXXUTILS_ALGORITHMS_H 
+#define CXXUTILS_ALGORITHMS_H 
+
+/**
+ *  @brief Copy the elements of a sequence for which a predicate is true.
+ *  @ingroup mutating_algorithms
+ *  @param  first   An input iterator.
+ *  @param  last    An input iterator.
+ *  @param  result  An output iterator.
+ *  @param  pred    A predicate.
+ *  @return   An iterator designating the end of the resulting sequence.
+ *
+ *  Copies each element in the range @p [first,last) for which
+ *  @p pred returns true to the range beginning at @p result.
+ *
+ *  copy_if() is stable, so the relative order of elements that are
+ *  copied is unchanged.
+ *
+ *  <i>Example</i>: 
+ *  @code
+ *  CxxUtils::copy_if( in.begin(), in.end(),
+ *                     std::back_inserter(out), filter );
+ *  @endcode
+ *      where in and out are STL-like containers and filter is a predicate
+ */
+
+namespace CxxUtils {
+
+template<typename _InputIterator, typename _OutputIterator,
+         typename _Predicate>
+_OutputIterator
+copy_if(_InputIterator __first, _InputIterator __last,
+	_OutputIterator __result, _Predicate __pred)
+{
+  for (; __first != __last; ++__first)
+    if (__pred(*__first)) {
+      *__result = *__first;
+      ++__result;
+    }
+  return __result;
+}
+
+}//> end CxxUtils namespace
+
+#endif //> CXXUTILS_ALGORITHMS_H
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.