Debian Codegraph @

Utilities/std/cm/string

raw
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 <algorithm>
9 #include <string> // IWYU pragma: export
10
11 #include <cm/bits/container_helpers.hxx> // IWYU pragma: export
12
13 namespace cm {
14
15 // should be updated when C++20 is finalized
16 #if (__cplusplus > 201703L || \
17 (defined(_MSVC_LANG) && _MSVC_LANG > 201703)) && \
18 defined(__cpp_lib_erase_if)
19
20 using std::erase;
21 using std::erase_if;
22
23 #else
24
25 template <typename T, typename Traits, typename Allocator, typename V>
26 inline void erase(std::basic_string<T, Traits, Allocator>& cont,
27 V const& value)
28 {
29 cont.erase(std::remove(cont.begin(), cont.end(), value), cont.end());
30 }
31
32 template <typename T, typename Traits, typename Allocator, typename Predicate>
33 inline void erase_if(std::basic_string<T, Traits, Allocator>& cont,
34 Predicate pred)
35 {
36 cont.erase(std::remove_if(cont.begin(), cont.end(), pred), cont.end());
37 }
38
39 #endif
40
41 } // namespace cm