Flutter Engine
 
Loading...
Searching...
No Matches
container_utils.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_CONTAINER_UTILS_H_
6#define BASE_CONTAINER_UTILS_H_
7
8#include <algorithm>
9#include <set>
10#include <vector>
11
12namespace base {
13
14template <class T, class Allocator, class Predicate>
15size_t EraseIf(std::vector<T, Allocator>& container, Predicate pred) {
16 auto it = std::remove_if(container.begin(), container.end(), pred);
17 size_t removed = std::distance(it, container.end());
18 container.erase(it, container.end());
19 return removed;
20}
21
22template <typename Container, typename Value>
23bool Contains(const Container& container, const Value& value) {
24 return container.find(value) != container.end();
25}
26
27template <typename T>
28bool Contains(const std::vector<T>& container, const T& value) {
29 return std::find(container.begin(), container.end(), value) !=
30 container.end();
31}
32
33} // namespace base
34
35#endif // BASE_CONTAINER_UTILS_H_
int32_t value
size_t EraseIf(std::vector< T, Allocator > &container, Predicate pred)
bool Contains(const Container &container, const Value &value)