Home | History | Annotate | Download | only in base

Lines Matching refs:Container

35 //  For a range within a container of pointers, calls delete
54 // STLDeleteElements() deletes all the elements in an STL container and clears
55 // the container. This function is suitable for use with a vector, set,
56 // hash_set, or any other STL container which defines sensible begin(), end(),
59 // If container is null, this function is a no-op.
62 // using a container of std::unique_ptr, which ensures that your container's
63 // elements are deleted when the container goes out of scope.
65 void STLDeleteElements(T *container) {
66 if (container != nullptr) {
67 STLDeleteContainerPointers(container->begin(), container->end());
68 container->clear();
72 // Given an STL container consisting of (key, value) pairs, STLDeleteValues
73 // deletes all the "value" components and clears the container. Does nothing
118 // Find index of the first element with the specified value known to be in the container.
119 template <typename Container, typename T>
120 size_t IndexOfElement(const Container& container, const T& value) {
121 auto it = std::find(container.begin(), container.end(), value);
122 DCHECK(it != container.end()); // Must exist.
123 return std::distance(container.begin(), it);
126 // Remove the first element with the specified value known to be in the container.
127 template <typename Container, typename T>
128 void RemoveElement(Container& container, const T& value) {
129 auto it = std::find(container.begin(), container.end(), value);
130 DCHECK(it != container.end()); // Must exist.
131 container.erase(it);
134 // Replace the first element with the specified old_value known to be in the container.
135 template <typename Container, typename T>
136 void ReplaceElement(Container& container, const T& old_value, const T& new_value) {
137 auto it = std::find(container.begin(), container.end(), old_value);
138 DCHECK(it != container.end()); // Must exist.
143 template <typename Container, typename T>
144 bool ContainsElement(const Container& container, const T& value, size_t start_pos = 0u) {
145 DCHECK_LE(start_pos, container.size());
146 auto start = container.begin();
148 auto it = std::find(start, container.end(), value);
149 return it != container.end();
160 // It can be used with any container which works with range-based for loop.