diff options
author | Patrick Williams <iawillia@us.ibm.com> | 2011-05-23 10:18:24 -0500 |
---|---|---|
committer | Douglas R. Gilbert <dgilbert@us.ibm.com> | 2011-05-23 11:26:14 -0500 |
commit | 50e70ce9facb233be4158569c11dc8b64d4297b2 (patch) | |
tree | 08c063be0a68171757ad01c32e78722a0ba236e0 | |
parent | 5240aadc816acdd255e1c6d65fefbcca079d8ad3 (diff) | |
download | talos-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>
-rw-r--r-- | src/include/algorithm | 28 |
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 |