Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/QtCore/q20map.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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