Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
q20map.h
Go to the documentation of this file.
1// Copyright (C) 2023 Ahmad Samir <a.samirh78@gmail.com>
2// Copyright (C) 2023 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#ifndef Q20MAP_H
7#define Q20MAP_H
8
9#include <QtCore/qtconfigmacros.h>
10
11#include <map>
12#if __has_include(<memory_resource>)
13# include <memory_resource>
14#endif
15
16//
17// W A R N I N G
18// -------------
19//
20// This file is not part of the Qt API. Types and functions defined in this
21// file can reliably be replaced by their std counterparts, once available.
22// You may use these definitions in your own code, but be aware that we
23// will remove them once Qt depends on the C++ version that supports
24// them in namespace std. There will be NO deprecation warning, the
25// definitions will JUST go away.
26//
27// If you can't agree to these terms, don't use these definitions!
28//
29// We mean it.
30//
31
32QT_BEGIN_NAMESPACE
33
34namespace q20 {
35// like std::erase/std::erase_if for std::map
36#if defined(__cpp_lib_erase_if) && __cpp_lib_erase_if >= 202002L // the one returning size_type
37using std::erase_if;
38#else
39
40// Make it more specialized than the compiler's, so that our implementation is preferred over
41// the compiler's (which may be present, but return void instead of the number of erased elements).
42
43#define MAKE_OVERLOAD(map, allocator)
44 template <typename Key, typename T, typename Compare, typename Pred>
45 constexpr typename std::map<Key, T, Compare, std::allocator<std::pair<const Key, T>>>::size_type
46 erase_if(std::map<Key, T, Compare, std::allocator<std::pair<const Key, T>>> &c, Pred p)
47 {
48 const auto origSize = c.size();
49 for (auto it = c.begin(), end = c.end(); it != end; /* erasing */) {
50 if (p(*it))
51 it = c.erase(it);
52 else
53 ++it;
54 }
55 return origSize - c.size();
56 }
57 /* end */
58
59MAKE_OVERLOAD(map, allocator)
60MAKE_OVERLOAD(multimap, allocator)
61#ifdef __cpp_lib_polymorphic_allocator
64#endif // __cpp_lib_polymorphic_allocator
65
66#undef MAKE_OVERLOAD
67
68#endif // __cpp_lib_erase_if
69} // namespace q20
70
71QT_END_NAMESPACE
72
73#endif /* Q20MAP_H */
#define MAKE_OVERLOAD(map, allocator)
Definition q20map.h:43
#define __has_include(x)