From 50e70ce9facb233be4158569c11dc8b64d4297b2 Mon Sep 17 00:00:00 2001 From: Patrick Williams Date: Mon, 23 May 2011 10:18:24 -0500 Subject: 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 Reviewed-by: Douglas R. Gilbert --- src/include/algorithm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/include/algorithm') 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 + inline InputIterator + find(InputIterator first, InputIterator last, + const EqualityComparable& value) + { + while(first != last) + { + if ((*first) == value) + return first; + + first++; + } + + return last; + } }; #endif -- cgit v1.2.3