Flutter Engine
The Flutter Engine
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 <set>
9#include <vector>
10
11namespace base {
12
13template <class T, class Allocator, class Predicate>
14size_t EraseIf(std::vector<T, Allocator>& container, Predicate pred) {
15 auto it = std::remove_if(container.begin(), container.end(), pred);
16 size_t removed = std::distance(it, container.end());
17 container.erase(it, container.end());
18 return removed;
19}
20
21template <typename Container, typename Value>
22bool Contains(const Container& container, const Value& value) {
23 return container.find(value) != container.end();
24}
25
26template <typename T>
27bool Contains(const std::vector<T>& container, const T& value) {
28 return std::find(container.begin(), container.end(), value) !=
29 container.end();
30}
31
32} // namespace base
33
34#endif // BASE_CONTAINER_UTILS_H_
int find(T *array, int N, T item)
uint8_t value
size_t EraseIf(std::vector< T, Allocator > &container, Predicate pred)
bool Contains(const Container &container, const Value &value)
#define T
Definition: precompiler.cc:65