1// -*-c++-*-
2// vim: set ft=cpp:
3
4/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
5   file Copyright.txt or https://cmake.org/licensing for details.  */
6#pragma once
7
8#include <list> // IWYU pragma: export
9
10namespace cm {
11
12// should be updated when C++20 is finalized
13#if (__cplusplus > 201703L ||                                                 \
14     (defined(_MSVC_LANG) && _MSVC_LANG > 201703)) &&                         \
15  defined(__cpp_lib_erase_if)
16
17using std::erase;
18using std::erase_if;
19
20#else
21
22template <typename T, typename Allocator, typename V>
23inline void erase(std::list<T, Allocator>& cont, const V& value)
24{
25  cont.remove_if([&](auto& elem) { return elem == value; });
26}
27
28template <typename T, typename Allocator, typename Predicate>
29inline void erase_if(std::list<T, Allocator>& cont, Predicate pred)
30{
31  cont.remove_if(pred);
32}
33
34#endif
35
36} // namespace cm
37