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