Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 09:31:59

0001 // Copyright (C) 2023 Ahmad Samir <a.samirh78@gmail.com>
0002 // Copyright (C) 2023 The Qt Company Ltd.
0003 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0004 // Qt-Security score:significant reason:default
0005 
0006 #ifndef Q20MAP_H
0007 #define Q20MAP_H
0008 
0009 #include <QtCore/qtconfigmacros.h>
0010 
0011 #include <map>
0012 #if __has_include(<memory_resource>)
0013 #  include <memory_resource>
0014 #endif
0015 
0016 //
0017 //  W A R N I N G
0018 //  -------------
0019 //
0020 // This file is not part of the Qt API. Types and functions defined in this
0021 // file can reliably be replaced by their std counterparts, once available.
0022 // You may use these definitions in your own code, but be aware that we
0023 // will remove them once Qt depends on the C++ version that supports
0024 // them in namespace std. There will be NO deprecation warning, the
0025 // definitions will JUST go away.
0026 //
0027 // If you can't agree to these terms, don't use these definitions!
0028 //
0029 // We mean it.
0030 //
0031 
0032 QT_BEGIN_NAMESPACE
0033 
0034 namespace q20 {
0035 // like std::erase/std::erase_if for std::map
0036 #if defined(__cpp_lib_erase_if) && __cpp_lib_erase_if >= 202002L // the one returning size_type
0037 using std::erase_if;
0038 #else
0039 
0040 // Make it more specialized than the compiler's, so that our implementation is preferred over
0041 // the compiler's (which may be present, but return void instead of the number of erased elements).
0042 
0043 #define MAKE_OVERLOAD(map, allocator) \
0044     template <typename Key, typename T, typename Compare, typename Pred> \
0045     constexpr typename std::map<Key, T, Compare, std::allocator<std::pair<const Key, T>>>::size_type \
0046     erase_if(std::map<Key, T, Compare, std::allocator<std::pair<const Key, T>>> &c, Pred p) \
0047     { \
0048         const auto origSize = c.size(); \
0049         for (auto it = c.begin(), end = c.end(); it != end; /* erasing */) { \
0050             if (p(*it)) \
0051                 it = c.erase(it); \
0052             else \
0053                 ++it; \
0054         } \
0055         return origSize - c.size(); \
0056     } \
0057     /* end */
0058 
0059 MAKE_OVERLOAD(map, allocator)
0060 MAKE_OVERLOAD(multimap, allocator)
0061 #ifdef __cpp_lib_polymorphic_allocator
0062 MAKE_OVERLOAD(map, pmr::polymorphic_allocator)
0063 MAKE_OVERLOAD(multimap, pmr::polymorphic_allocator)
0064 #endif // __cpp_lib_polymorphic_allocator
0065 
0066 #undef MAKE_OVERLOAD
0067 
0068 #endif // __cpp_lib_erase_if
0069 } // namespace q20
0070 
0071 QT_END_NAMESPACE
0072 
0073 #endif /* Q20MAP_H */