Index: base/values.cc |
diff --git a/base/values.cc b/base/values.cc |
index 17aba167a1f7cf42dfd9d3bac05fbee00b85d5ab..60b0d70f1ed07f7a92c1f6ca7f5815dae3c38fa6 100644 |
--- a/base/values.cc |
+++ b/base/values.cc |
@@ -4,6 +4,8 @@ |
#include "base/values.h" |
+#include <algorithm> |
+ |
#include "base/float_util.h" |
#include "base/logging.h" |
#include "base/string_util.h" |
@@ -58,6 +60,22 @@ Value* CopyWithoutEmptyChildren(Value* node) { |
} |
} |
+// A small functor for comparing Values for std::find_if and similar. |
+class ValueEquals { |
+ public: |
+ // Pass the value against which all consecutive calls of the () operator will |
+ // compare their argument to. This Value object must not be destroyed while |
+ // the ValueEquals is in use. |
+ ValueEquals(const Value* first) : first_(first) { } |
+ |
+ bool operator ()(const Value* second) const { |
+ return first_->Equals(second); |
+ } |
+ |
+ private: |
+ const Value* first_; |
+}; |
+ |
} // namespace |
namespace base { |
@@ -865,6 +883,10 @@ bool ListValue::Insert(size_t index, Value* in_value) { |
return true; |
} |
+ListValue::const_iterator ListValue::Find(const Value& value) const { |
+ return std::find_if(list_.begin(), list_.end(), ValueEquals(&value)); |
+} |
+ |
bool ListValue::GetAsList(ListValue** out_value) { |
if (out_value) |
*out_value = this; |