From bfbbdfad59bd9488e8deeed193d318012de66826 Mon Sep 17 00:00:00 2001 From: cantor Date: Wed, 14 Nov 2007 05:22:38 +0000 Subject: [PATCH] Add non-const algorithm. git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/trunk@436 de75baf8-a10c-0410-a50a-987c0e22f00f --- xmltooling/util/Predicates.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/xmltooling/util/Predicates.h b/xmltooling/util/Predicates.h index e8e6169..b822862 100644 --- a/xmltooling/util/Predicates.h +++ b/xmltooling/util/Predicates.h @@ -96,7 +96,20 @@ namespace xmltooling { typename Container::const_iterator i = std::find_if(c.begin(), c.end(), p); return (i!=c.end()) ? *i : NULL; } - + + /** + * Template algorithm returns first pointer element from a container that matches a predicate. + * + * @param c read-only container of pointer-based objects + * @param p a predicate function + * @return the first object in the container matching the predicate, or NULL + */ + template + typename Container::value_type find_if(Container& c, const Predicate& p) { + typename Container::iterator i = std::find_if(c.begin(), c.end(), p); + return (i!=c.end()) ? *i : NULL; + } + }; #endif /* __xmltooling_predicates_h__ */ -- 2.1.4