Misuse of typename.
[shibboleth/xmltooling.git] / xmltooling / util / Predicates.h
index 2453a62..e8e6169 100644 (file)
@@ -48,7 +48,7 @@ namespace xmltooling {
          * 
          * @param xmlObject the object to examine
          */
-        bool operator()(const XMLObject* xmlObject) {
+        bool operator()(const XMLObject* xmlObject) const {
             return xmlObject ? (xmlObject->getElementQName() == m_q) : false;
         }
         
@@ -75,7 +75,7 @@ namespace xmltooling {
          * 
          * @param xmlObject the object to examine
          */
-        bool operator()(const XMLObject* xmlObject) {
+        bool operator()(const XMLObject* xmlObject) const {
             const QName* xsitype = xmlObject ? xmlObject->getSchemaType() : NULL;
             return xsitype ? (*xsitype == m_q) : false;
         }
@@ -83,7 +83,20 @@ namespace xmltooling {
     private:
         const QName& m_q;
     };
-        
+
+    /**
+     * 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, typename Predicate>
+    typename Container::value_type find_if(const Container& c, const Predicate& p) {
+        typename Container::const_iterator i = std::find_if(c.begin(), c.end(), p);
+        return (i!=c.end()) ? *i : NULL;
+    }
+    
 };
 
 #endif /* __xmltooling_predicates_h__ */