From 1cb192bf3da88c97e7622d4813053a4ca916044e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 28 Jan 2022 00:21:27 +0100 Subject: [PATCH] QFlatMap: replace manual const_cast<>s with std::as_const MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Shorter, because it doesn't need to name the type. As a drive-by, replace all remaining uses of the private full_map_t alias with 'QFlatMap', the class name, which, also in templates, refers to the class, not the class template. Pick-to: 6.3 6.2 Change-Id: Ie3bada43d9d28a84543e8baa8a36c522dff80b9e Reviewed-by: Edward Welbourne Reviewed-by: Fabian Kosmale Reviewed-by: Jörg Bornemann --- src/corelib/tools/qflatmap_p.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/corelib/tools/qflatmap_p.h b/src/corelib/tools/qflatmap_p.h index 17c6167ddf..acfcf5e778 100644 --- a/src/corelib/tools/qflatmap_p.h +++ b/src/corelib/tools/qflatmap_p.h @@ -111,8 +111,6 @@ class QFlatMap : private QFlatMapValueCompare { static_assert(std::is_nothrow_destructible_v, "Types with throwing destructors are not supported in Qt containers."); - using full_map_t = QFlatMap; - template class mock_pointer { @@ -274,7 +272,7 @@ public: private: containers *c = nullptr; size_type i = 0; - friend full_map_t; + friend QFlatMap; }; class const_iterator @@ -411,7 +409,7 @@ public: private: const containers *c = nullptr; size_type i = 0; - friend full_map_t; + friend QFlatMap; }; private: @@ -790,14 +788,14 @@ public: iterator lower_bound(const Key &key) { - auto cit = const_cast(this)->lower_bound(key); + auto cit = std::as_const(*this).lower_bound(key); return { &c, cit.i }; } template = nullptr> iterator lower_bound(const X &key) { - auto cit = const_cast(this)->lower_bound(key); + auto cit = std::as_const(*this).lower_bound(key); return { &c, cit.i }; } @@ -880,7 +878,7 @@ private: class IndexedKeyComparator { public: - IndexedKeyComparator(const full_map_t *am) + IndexedKeyComparator(const QFlatMap *am) : m(am) { } @@ -891,7 +889,7 @@ private: } private: - const full_map_t *m; + const QFlatMap *m; }; template @@ -914,7 +912,7 @@ private: iterator binary_find(const Key &key) { - return { &c, const_cast(this)->binary_find(key).i }; + return { &c, std::as_const(*this).binary_find(key).i }; } const_iterator binary_find(const Key &key) const