Chromium Code Reviews| Index: base/values.cc |
| diff --git a/base/values.cc b/base/values.cc |
| index 17aba167a1f7cf42dfd9d3bac05fbee00b85d5ab..f53fc3c0705ef99fff00b1b26f78461762d15c9c 100644 |
| --- a/base/values.cc |
| +++ b/base/values.cc |
| @@ -58,6 +58,19 @@ Value* CopyWithoutEmptyChildren(Value* node) { |
| } |
| } |
| +// A small functor for comparing Values for std::find_if and similar. |
| +class CompareValues { |
|
Mattias Nissler (ping if slow)
2011/09/15 13:40:39
Maybe ValueEquals? It isn't really useful as a com
pastarmovj
2011/09/16 08:03:49
Done. Actually picked something even more specific
|
| + public: |
| + CompareValues(const Value& first) : first_(first) { } |
| + |
| + bool operator ()(const Value* second) const { |
| + return first_.Equals(second); |
| + } |
| + |
| + private: |
| + const Value& first_; |
|
Mattias Nissler (ping if slow)
2011/09/15 13:40:39
In chromium, we'd usually use a pointer for this.
pastarmovj
2011/09/16 08:03:49
Done.
|
| +}; |
| + |
| } // namespace |
| namespace base { |
| @@ -865,6 +878,11 @@ bool ListValue::Insert(size_t index, Value* in_value) { |
| return true; |
| } |
| +ListValue::const_iterator ListValue::Find(const Value& value) const { |
| + CompareValues compare(value); |
| + return std::find_if(list_.begin(), list_.end(), compare); |
| +} |
| + |
| bool ListValue::GetAsList(ListValue** out_value) { |
| if (out_value) |
| *out_value = this; |