summaryrefslogtreecommitdiffstats
path: root/src/include/algorithm
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2011-05-23 10:18:24 -0500
committerDouglas R. Gilbert <dgilbert@us.ibm.com>2011-05-23 11:26:14 -0500
commit50e70ce9facb233be4158569c11dc8b64d4297b2 (patch)
tree08c063be0a68171757ad01c32e78722a0ba236e0 /src/include/algorithm
parent5240aadc816acdd255e1c6d65fefbcca079d8ad3 (diff)
downloadtalos-hostboot-50e70ce9facb233be4158569c11dc8b64d4297b2.tar.gz
talos-hostboot-50e70ce9facb233be4158569c11dc8b64d4297b2.zip
Add container find to algorithm.
Change-Id: Ic0b0e542b6608b2a9495c99fbf9659c7553914f7 Reviewed-on: http://gfwr801.rchland.ibm.com:8080/gerrit/94 Tested-by: Jenkins Server Reviewed-by: Andrew J. Geissler <andrewg@us.ibm.com> Reviewed-by: Douglas R. Gilbert <dgilbert@us.ibm.com>
Diffstat (limited to 'src/include/algorithm')
-rw-r--r--src/include/algorithm28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/include/algorithm b/src/include/algorithm
index 9bf0aa006..17c9380a3 100644
--- a/src/include/algorithm
+++ b/src/include/algorithm
@@ -126,6 +126,34 @@ namespace std
if(a < b) return b;
return a;
}
+
+ /**
+ * Find the location of an element within a range.
+ * @param[in] first InputIterator to the first position in the range.
+ * @param[in] last InputIterator to the last position in the range.
+ * @param[in] value Value to use for comparison.
+ *
+ * Returns the first iterator i in the range [first,last) such that
+ * (*i == value) or else last if no element is found.
+ *
+ * @return An iterator in the range [first,last]. last implies that no
+ * matching element was found.
+ */
+ template <typename InputIterator, typename EqualityComparable>
+ inline InputIterator
+ find(InputIterator first, InputIterator last,
+ const EqualityComparable& value)
+ {
+ while(first != last)
+ {
+ if ((*first) == value)
+ return first;
+
+ first++;
+ }
+
+ return last;
+ }
};
#endif
OpenPOWER on IntegriCloud