1 // Copyright 2018 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // -----------------------------------------------------------------------------
16 // File: btree_set.h
17 // -----------------------------------------------------------------------------
18 //
19 // This header file defines B-tree sets: sorted associative containers of
20 // values.
21 //
22 // * `absl::btree_set<>`
23 // * `absl::btree_multiset<>`
24 //
25 // These B-tree types are similar to the corresponding types in the STL
26 // (`std::set` and `std::multiset`) and generally conform to the STL interfaces
27 // of those types. However, because they are implemented using B-trees, they
28 // are more efficient in most situations.
29 //
30 // Unlike `std::set` and `std::multiset`, which are commonly implemented using
31 // red-black tree nodes, B-tree sets use more generic B-tree nodes able to hold
32 // multiple values per node. Holding multiple values per node often makes
33 // B-tree sets perform better than their `std::set` counterparts, because
34 // multiple entries can be checked within the same cache hit.
35 //
36 // However, these types should not be considered drop-in replacements for
37 // `std::set` and `std::multiset` as there are some API differences, which are
38 // noted in this header file.
39 //
40 // Importantly, insertions and deletions may invalidate outstanding iterators,
41 // pointers, and references to elements. Such invalidations are typically only
42 // an issue if insertion and deletion operations are interleaved with the use of
43 // more than one iterator, pointer, or reference simultaneously. For this
44 // reason, `insert()` and `erase()` return a valid iterator at the current
45 // position.
46
47 #ifndef ABSL_CONTAINER_BTREE_SET_H_
48 #define ABSL_CONTAINER_BTREE_SET_H_
49
50 #include "absl/container/internal/btree.h" // IWYU pragma: export
51 #include "absl/container/internal/btree_container.h" // IWYU pragma: export
52
53 namespace absl {
54 ABSL_NAMESPACE_BEGIN
55
56 // absl::btree_set<>
57 //
58 // An `absl::btree_set<K>` is an ordered associative container of unique key
59 // values designed to be a more efficient replacement for `std::set` (in most
60 // cases).
61 //
62 // Keys are sorted using an (optional) comparison function, which defaults to
63 // `std::less<K>`.
64 //
65 // An `absl::btree_set<K>` uses a default allocator of `std::allocator<K>` to
66 // allocate (and deallocate) nodes, and construct and destruct values within
67 // those nodes. You may instead specify a custom allocator `A` (which in turn
68 // requires specifying a custom comparator `C`) as in
69 // `absl::btree_set<K, C, A>`.
70 //
71 template <typename Key, typename Compare = std::less<Key>,
72 typename Alloc = std::allocator<Key>>
73 class btree_set
74 : public container_internal::btree_set_container<
75 container_internal::btree<container_internal::set_params<
76 Key, Compare, Alloc, /*TargetNodeSize=*/256,
77 /*Multi=*/false>>> {
78 using Base = typename btree_set::btree_set_container;
79
80 public:
81 // Constructors and Assignment Operators
82 //
83 // A `btree_set` supports the same overload set as `std::set`
84 // for construction and assignment:
85 //
86 // * Default constructor
87 //
88 // absl::btree_set<std::string> set1;
89 //
90 // * Initializer List constructor
91 //
92 // absl::btree_set<std::string> set2 =
93 // {{"huey"}, {"dewey"}, {"louie"},};
94 //
95 // * Copy constructor
96 //
97 // absl::btree_set<std::string> set3(set2);
98 //
99 // * Copy assignment operator
100 //
101 // absl::btree_set<std::string> set4;
102 // set4 = set3;
103 //
104 // * Move constructor
105 //
106 // // Move is guaranteed efficient
107 // absl::btree_set<std::string> set5(std::move(set4));
108 //
109 // * Move assignment operator
110 //
111 // // May be efficient if allocators are compatible
112 // absl::btree_set<std::string> set6;
113 // set6 = std::move(set5);
114 //
115 // * Range constructor
116 //
117 // std::vector<std::string> v = {"a", "b"};
118 // absl::btree_set<std::string> set7(v.begin(), v.end());
btree_set()119 btree_set() {}
120 using Base::Base;
121
122 // btree_set::begin()
123 //
124 // Returns an iterator to the beginning of the `btree_set`.
125 using Base::begin;
126
127 // btree_set::cbegin()
128 //
129 // Returns a const iterator to the beginning of the `btree_set`.
130 using Base::cbegin;
131
132 // btree_set::end()
133 //
134 // Returns an iterator to the end of the `btree_set`.
135 using Base::end;
136
137 // btree_set::cend()
138 //
139 // Returns a const iterator to the end of the `btree_set`.
140 using Base::cend;
141
142 // btree_set::empty()
143 //
144 // Returns whether or not the `btree_set` is empty.
145 using Base::empty;
146
147 // btree_set::max_size()
148 //
149 // Returns the largest theoretical possible number of elements within a
150 // `btree_set` under current memory constraints. This value can be thought
151 // of as the largest value of `std::distance(begin(), end())` for a
152 // `btree_set<Key>`.
153 using Base::max_size;
154
155 // btree_set::size()
156 //
157 // Returns the number of elements currently within the `btree_set`.
158 using Base::size;
159
160 // btree_set::clear()
161 //
162 // Removes all elements from the `btree_set`. Invalidates any references,
163 // pointers, or iterators referring to contained elements.
164 using Base::clear;
165
166 // btree_set::erase()
167 //
168 // Erases elements within the `btree_set`. Overloads are listed below.
169 //
170 // iterator erase(iterator position):
171 // iterator erase(const_iterator position):
172 //
173 // Erases the element at `position` of the `btree_set`, returning
174 // the iterator pointing to the element after the one that was erased
175 // (or end() if none exists).
176 //
177 // iterator erase(const_iterator first, const_iterator last):
178 //
179 // Erases the elements in the open interval [`first`, `last`), returning
180 // the iterator pointing to the element after the interval that was erased
181 // (or end() if none exists).
182 //
183 // template <typename K> size_type erase(const K& key):
184 //
185 // Erases the element with the matching key, if it exists, returning the
186 // number of elements erased (0 or 1).
187 using Base::erase;
188
189 // btree_set::insert()
190 //
191 // Inserts an element of the specified value into the `btree_set`,
192 // returning an iterator pointing to the newly inserted element, provided that
193 // an element with the given key does not already exist. If an insertion
194 // occurs, any references, pointers, or iterators are invalidated.
195 // Overloads are listed below.
196 //
197 // std::pair<iterator,bool> insert(const value_type& value):
198 //
199 // Inserts a value into the `btree_set`. Returns a pair consisting of an
200 // iterator to the inserted element (or to the element that prevented the
201 // insertion) and a bool denoting whether the insertion took place.
202 //
203 // std::pair<iterator,bool> insert(value_type&& value):
204 //
205 // Inserts a moveable value into the `btree_set`. Returns a pair
206 // consisting of an iterator to the inserted element (or to the element that
207 // prevented the insertion) and a bool denoting whether the insertion took
208 // place.
209 //
210 // iterator insert(const_iterator hint, const value_type& value):
211 // iterator insert(const_iterator hint, value_type&& value):
212 //
213 // Inserts a value, using the position of `hint` as a non-binding suggestion
214 // for where to begin the insertion search. Returns an iterator to the
215 // inserted element, or to the existing element that prevented the
216 // insertion.
217 //
218 // void insert(InputIterator first, InputIterator last):
219 //
220 // Inserts a range of values [`first`, `last`).
221 //
222 // void insert(std::initializer_list<init_type> ilist):
223 //
224 // Inserts the elements within the initializer list `ilist`.
225 using Base::insert;
226
227 // btree_set::emplace()
228 //
229 // Inserts an element of the specified value by constructing it in-place
230 // within the `btree_set`, provided that no element with the given key
231 // already exists.
232 //
233 // The element may be constructed even if there already is an element with the
234 // key in the container, in which case the newly constructed element will be
235 // destroyed immediately.
236 //
237 // If an insertion occurs, any references, pointers, or iterators are
238 // invalidated.
239 using Base::emplace;
240
241 // btree_set::emplace_hint()
242 //
243 // Inserts an element of the specified value by constructing it in-place
244 // within the `btree_set`, using the position of `hint` as a non-binding
245 // suggestion for where to begin the insertion search, and only inserts
246 // provided that no element with the given key already exists.
247 //
248 // The element may be constructed even if there already is an element with the
249 // key in the container, in which case the newly constructed element will be
250 // destroyed immediately.
251 //
252 // If an insertion occurs, any references, pointers, or iterators are
253 // invalidated.
254 using Base::emplace_hint;
255
256 // btree_set::extract()
257 //
258 // Extracts the indicated element, erasing it in the process, and returns it
259 // as a C++17-compatible node handle. Overloads are listed below.
260 //
261 // node_type extract(const_iterator position):
262 //
263 // Extracts the element at the indicated position and returns a node handle
264 // owning that extracted data.
265 //
266 // template <typename K> node_type extract(const K& k):
267 //
268 // Extracts the element with the key matching the passed key value and
269 // returns a node handle owning that extracted data. If the `btree_set`
270 // does not contain an element with a matching key, this function returns an
271 // empty node handle.
272 //
273 // NOTE: In this context, `node_type` refers to the C++17 concept of a
274 // move-only type that owns and provides access to the elements in associative
275 // containers (https://en.cppreference.com/w/cpp/container/node_handle).
276 // It does NOT refer to the data layout of the underlying btree.
277 using Base::extract;
278
279 // btree_set::merge()
280 //
281 // Extracts elements from a given `source` btree_set into this
282 // `btree_set`. If the destination `btree_set` already contains an
283 // element with an equivalent key, that element is not extracted.
284 using Base::merge;
285
286 // btree_set::swap(btree_set& other)
287 //
288 // Exchanges the contents of this `btree_set` with those of the `other`
289 // btree_set, avoiding invocation of any move, copy, or swap operations on
290 // individual elements.
291 //
292 // All iterators and references on the `btree_set` remain valid, excepting
293 // for the past-the-end iterator, which is invalidated.
294 using Base::swap;
295
296 // btree_set::contains()
297 //
298 // template <typename K> bool contains(const K& key) const:
299 //
300 // Determines whether an element comparing equal to the given `key` exists
301 // within the `btree_set`, returning `true` if so or `false` otherwise.
302 //
303 // Supports heterogeneous lookup, provided that the set has a compatible
304 // heterogeneous comparator.
305 using Base::contains;
306
307 // btree_set::count()
308 //
309 // template <typename K> size_type count(const K& key) const:
310 //
311 // Returns the number of elements comparing equal to the given `key` within
312 // the `btree_set`. Note that this function will return either `1` or `0`
313 // since duplicate elements are not allowed within a `btree_set`.
314 //
315 // Supports heterogeneous lookup, provided that the set has a compatible
316 // heterogeneous comparator.
317 using Base::count;
318
319 // btree_set::equal_range()
320 //
321 // Returns a closed range [first, last], defined by a `std::pair` of two
322 // iterators, containing all elements with the passed key in the
323 // `btree_set`.
324 using Base::equal_range;
325
326 // btree_set::find()
327 //
328 // template <typename K> iterator find(const K& key):
329 // template <typename K> const_iterator find(const K& key) const:
330 //
331 // Finds an element with the passed `key` within the `btree_set`.
332 //
333 // Supports heterogeneous lookup, provided that the set has a compatible
334 // heterogeneous comparator.
335 using Base::find;
336
337 // btree_set::lower_bound()
338 //
339 // template <typename K> iterator lower_bound(const K& key):
340 // template <typename K> const_iterator lower_bound(const K& key) const:
341 //
342 // Finds the first element that is not less than `key` within the `btree_set`.
343 //
344 // Supports heterogeneous lookup, provided that the set has a compatible
345 // heterogeneous comparator.
346 using Base::lower_bound;
347
348 // btree_set::upper_bound()
349 //
350 // template <typename K> iterator upper_bound(const K& key):
351 // template <typename K> const_iterator upper_bound(const K& key) const:
352 //
353 // Finds the first element that is greater than `key` within the `btree_set`.
354 //
355 // Supports heterogeneous lookup, provided that the set has a compatible
356 // heterogeneous comparator.
357 using Base::upper_bound;
358
359 // btree_set::get_allocator()
360 //
361 // Returns the allocator function associated with this `btree_set`.
362 using Base::get_allocator;
363
364 // btree_set::key_comp();
365 //
366 // Returns the key comparator associated with this `btree_set`.
367 using Base::key_comp;
368
369 // btree_set::value_comp();
370 //
371 // Returns the value comparator associated with this `btree_set`. The keys to
372 // sort the elements are the values themselves, therefore `value_comp` and its
373 // sibling member function `key_comp` are equivalent.
374 using Base::value_comp;
375 };
376
377 // absl::swap(absl::btree_set<>, absl::btree_set<>)
378 //
379 // Swaps the contents of two `absl::btree_set` containers.
380 template <typename K, typename C, typename A>
swap(btree_set<K,C,A> & x,btree_set<K,C,A> & y)381 void swap(btree_set<K, C, A> &x, btree_set<K, C, A> &y) {
382 return x.swap(y);
383 }
384
385 // absl::erase_if(absl::btree_set<>, Pred)
386 //
387 // Erases all elements that satisfy the predicate pred from the container.
388 template <typename K, typename C, typename A, typename Pred>
erase_if(btree_set<K,C,A> & set,Pred pred)389 void erase_if(btree_set<K, C, A> &set, Pred pred) {
390 for (auto it = set.begin(); it != set.end();) {
391 if (pred(*it)) {
392 it = set.erase(it);
393 } else {
394 ++it;
395 }
396 }
397 }
398
399 // absl::btree_multiset<>
400 //
401 // An `absl::btree_multiset<K>` is an ordered associative container of
402 // keys and associated values designed to be a more efficient replacement
403 // for `std::multiset` (in most cases). Unlike `absl::btree_set`, a B-tree
404 // multiset allows equivalent elements.
405 //
406 // Keys are sorted using an (optional) comparison function, which defaults to
407 // `std::less<K>`.
408 //
409 // An `absl::btree_multiset<K>` uses a default allocator of `std::allocator<K>`
410 // to allocate (and deallocate) nodes, and construct and destruct values within
411 // those nodes. You may instead specify a custom allocator `A` (which in turn
412 // requires specifying a custom comparator `C`) as in
413 // `absl::btree_multiset<K, C, A>`.
414 //
415 template <typename Key, typename Compare = std::less<Key>,
416 typename Alloc = std::allocator<Key>>
417 class btree_multiset
418 : public container_internal::btree_multiset_container<
419 container_internal::btree<container_internal::set_params<
420 Key, Compare, Alloc, /*TargetNodeSize=*/256,
421 /*Multi=*/true>>> {
422 using Base = typename btree_multiset::btree_multiset_container;
423
424 public:
425 // Constructors and Assignment Operators
426 //
427 // A `btree_multiset` supports the same overload set as `std::set`
428 // for construction and assignment:
429 //
430 // * Default constructor
431 //
432 // absl::btree_multiset<std::string> set1;
433 //
434 // * Initializer List constructor
435 //
436 // absl::btree_multiset<std::string> set2 =
437 // {{"huey"}, {"dewey"}, {"louie"},};
438 //
439 // * Copy constructor
440 //
441 // absl::btree_multiset<std::string> set3(set2);
442 //
443 // * Copy assignment operator
444 //
445 // absl::btree_multiset<std::string> set4;
446 // set4 = set3;
447 //
448 // * Move constructor
449 //
450 // // Move is guaranteed efficient
451 // absl::btree_multiset<std::string> set5(std::move(set4));
452 //
453 // * Move assignment operator
454 //
455 // // May be efficient if allocators are compatible
456 // absl::btree_multiset<std::string> set6;
457 // set6 = std::move(set5);
458 //
459 // * Range constructor
460 //
461 // std::vector<std::string> v = {"a", "b"};
462 // absl::btree_multiset<std::string> set7(v.begin(), v.end());
btree_multiset()463 btree_multiset() {}
464 using Base::Base;
465
466 // btree_multiset::begin()
467 //
468 // Returns an iterator to the beginning of the `btree_multiset`.
469 using Base::begin;
470
471 // btree_multiset::cbegin()
472 //
473 // Returns a const iterator to the beginning of the `btree_multiset`.
474 using Base::cbegin;
475
476 // btree_multiset::end()
477 //
478 // Returns an iterator to the end of the `btree_multiset`.
479 using Base::end;
480
481 // btree_multiset::cend()
482 //
483 // Returns a const iterator to the end of the `btree_multiset`.
484 using Base::cend;
485
486 // btree_multiset::empty()
487 //
488 // Returns whether or not the `btree_multiset` is empty.
489 using Base::empty;
490
491 // btree_multiset::max_size()
492 //
493 // Returns the largest theoretical possible number of elements within a
494 // `btree_multiset` under current memory constraints. This value can be
495 // thought of as the largest value of `std::distance(begin(), end())` for a
496 // `btree_multiset<Key>`.
497 using Base::max_size;
498
499 // btree_multiset::size()
500 //
501 // Returns the number of elements currently within the `btree_multiset`.
502 using Base::size;
503
504 // btree_multiset::clear()
505 //
506 // Removes all elements from the `btree_multiset`. Invalidates any references,
507 // pointers, or iterators referring to contained elements.
508 using Base::clear;
509
510 // btree_multiset::erase()
511 //
512 // Erases elements within the `btree_multiset`. Overloads are listed below.
513 //
514 // iterator erase(iterator position):
515 // iterator erase(const_iterator position):
516 //
517 // Erases the element at `position` of the `btree_multiset`, returning
518 // the iterator pointing to the element after the one that was erased
519 // (or end() if none exists).
520 //
521 // iterator erase(const_iterator first, const_iterator last):
522 //
523 // Erases the elements in the open interval [`first`, `last`), returning
524 // the iterator pointing to the element after the interval that was erased
525 // (or end() if none exists).
526 //
527 // template <typename K> size_type erase(const K& key):
528 //
529 // Erases the elements matching the key, if any exist, returning the
530 // number of elements erased.
531 using Base::erase;
532
533 // btree_multiset::insert()
534 //
535 // Inserts an element of the specified value into the `btree_multiset`,
536 // returning an iterator pointing to the newly inserted element.
537 // Any references, pointers, or iterators are invalidated. Overloads are
538 // listed below.
539 //
540 // iterator insert(const value_type& value):
541 //
542 // Inserts a value into the `btree_multiset`, returning an iterator to the
543 // inserted element.
544 //
545 // iterator insert(value_type&& value):
546 //
547 // Inserts a moveable value into the `btree_multiset`, returning an iterator
548 // to the inserted element.
549 //
550 // iterator insert(const_iterator hint, const value_type& value):
551 // iterator insert(const_iterator hint, value_type&& value):
552 //
553 // Inserts a value, using the position of `hint` as a non-binding suggestion
554 // for where to begin the insertion search. Returns an iterator to the
555 // inserted element.
556 //
557 // void insert(InputIterator first, InputIterator last):
558 //
559 // Inserts a range of values [`first`, `last`).
560 //
561 // void insert(std::initializer_list<init_type> ilist):
562 //
563 // Inserts the elements within the initializer list `ilist`.
564 using Base::insert;
565
566 // btree_multiset::emplace()
567 //
568 // Inserts an element of the specified value by constructing it in-place
569 // within the `btree_multiset`. Any references, pointers, or iterators are
570 // invalidated.
571 using Base::emplace;
572
573 // btree_multiset::emplace_hint()
574 //
575 // Inserts an element of the specified value by constructing it in-place
576 // within the `btree_multiset`, using the position of `hint` as a non-binding
577 // suggestion for where to begin the insertion search.
578 //
579 // Any references, pointers, or iterators are invalidated.
580 using Base::emplace_hint;
581
582 // btree_multiset::extract()
583 //
584 // Extracts the indicated element, erasing it in the process, and returns it
585 // as a C++17-compatible node handle. Overloads are listed below.
586 //
587 // node_type extract(const_iterator position):
588 //
589 // Extracts the element at the indicated position and returns a node handle
590 // owning that extracted data.
591 //
592 // template <typename K> node_type extract(const K& k):
593 //
594 // Extracts the element with the key matching the passed key value and
595 // returns a node handle owning that extracted data. If the `btree_multiset`
596 // does not contain an element with a matching key, this function returns an
597 // empty node handle.
598 //
599 // NOTE: In this context, `node_type` refers to the C++17 concept of a
600 // move-only type that owns and provides access to the elements in associative
601 // containers (https://en.cppreference.com/w/cpp/container/node_handle).
602 // It does NOT refer to the data layout of the underlying btree.
603 using Base::extract;
604
605 // btree_multiset::merge()
606 //
607 // Extracts all elements from a given `source` btree_multiset into this
608 // `btree_multiset`.
609 using Base::merge;
610
611 // btree_multiset::swap(btree_multiset& other)
612 //
613 // Exchanges the contents of this `btree_multiset` with those of the `other`
614 // btree_multiset, avoiding invocation of any move, copy, or swap operations
615 // on individual elements.
616 //
617 // All iterators and references on the `btree_multiset` remain valid,
618 // excepting for the past-the-end iterator, which is invalidated.
619 using Base::swap;
620
621 // btree_multiset::contains()
622 //
623 // template <typename K> bool contains(const K& key) const:
624 //
625 // Determines whether an element comparing equal to the given `key` exists
626 // within the `btree_multiset`, returning `true` if so or `false` otherwise.
627 //
628 // Supports heterogeneous lookup, provided that the set has a compatible
629 // heterogeneous comparator.
630 using Base::contains;
631
632 // btree_multiset::count()
633 //
634 // template <typename K> size_type count(const K& key) const:
635 //
636 // Returns the number of elements comparing equal to the given `key` within
637 // the `btree_multiset`.
638 //
639 // Supports heterogeneous lookup, provided that the set has a compatible
640 // heterogeneous comparator.
641 using Base::count;
642
643 // btree_multiset::equal_range()
644 //
645 // Returns a closed range [first, last], defined by a `std::pair` of two
646 // iterators, containing all elements with the passed key in the
647 // `btree_multiset`.
648 using Base::equal_range;
649
650 // btree_multiset::find()
651 //
652 // template <typename K> iterator find(const K& key):
653 // template <typename K> const_iterator find(const K& key) const:
654 //
655 // Finds an element with the passed `key` within the `btree_multiset`.
656 //
657 // Supports heterogeneous lookup, provided that the set has a compatible
658 // heterogeneous comparator.
659 using Base::find;
660
661 // btree_multiset::lower_bound()
662 //
663 // template <typename K> iterator lower_bound(const K& key):
664 // template <typename K> const_iterator lower_bound(const K& key) const:
665 //
666 // Finds the first element that is not less than `key` within the
667 // `btree_multiset`.
668 //
669 // Supports heterogeneous lookup, provided that the set has a compatible
670 // heterogeneous comparator.
671 using Base::lower_bound;
672
673 // btree_multiset::upper_bound()
674 //
675 // template <typename K> iterator upper_bound(const K& key):
676 // template <typename K> const_iterator upper_bound(const K& key) const:
677 //
678 // Finds the first element that is greater than `key` within the
679 // `btree_multiset`.
680 //
681 // Supports heterogeneous lookup, provided that the set has a compatible
682 // heterogeneous comparator.
683 using Base::upper_bound;
684
685 // btree_multiset::get_allocator()
686 //
687 // Returns the allocator function associated with this `btree_multiset`.
688 using Base::get_allocator;
689
690 // btree_multiset::key_comp();
691 //
692 // Returns the key comparator associated with this `btree_multiset`.
693 using Base::key_comp;
694
695 // btree_multiset::value_comp();
696 //
697 // Returns the value comparator associated with this `btree_multiset`. The
698 // keys to sort the elements are the values themselves, therefore `value_comp`
699 // and its sibling member function `key_comp` are equivalent.
700 using Base::value_comp;
701 };
702
703 // absl::swap(absl::btree_multiset<>, absl::btree_multiset<>)
704 //
705 // Swaps the contents of two `absl::btree_multiset` containers.
706 template <typename K, typename C, typename A>
swap(btree_multiset<K,C,A> & x,btree_multiset<K,C,A> & y)707 void swap(btree_multiset<K, C, A> &x, btree_multiset<K, C, A> &y) {
708 return x.swap(y);
709 }
710
711 // absl::erase_if(absl::btree_multiset<>, Pred)
712 //
713 // Erases all elements that satisfy the predicate pred from the container.
714 template <typename K, typename C, typename A, typename Pred>
erase_if(btree_multiset<K,C,A> & set,Pred pred)715 void erase_if(btree_multiset<K, C, A> &set, Pred pred) {
716 for (auto it = set.begin(); it != set.end();) {
717 if (pred(*it)) {
718 it = set.erase(it);
719 } else {
720 ++it;
721 }
722 }
723 }
724
725 ABSL_NAMESPACE_END
726 } // namespace absl
727
728 #endif // ABSL_CONTAINER_BTREE_SET_H_
729