diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2024-09-06 10:38:44 +0200 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2024-09-06 17:54:52 +0200 |
| commit | a338f67dceed61009375a4a90a7fe32a06b443a0 (patch) | |
| tree | b5076c88d9b30d2cf5240d36b3c1bef41c32cbc3 /src | |
| parent | 7fe3cee36352c74cbaaff52e863bd0da1170affa (diff) | |
Q(Multi)Hash: Fix underconstrained heterogenous operator[]
If the key doesn't exist yet in the map, we need to be able to create an
actual Key object. Consequently, we require that the type is actually
convertible.
This doesn't fix any broken code, but avoids compilation errors in QHash
internals bubbling up.
Note that the existence of a comomn_reference does not imply
convertibility (so the concept version wasn't strict enough either).
Done-with: Fabian Kosmale <fabian.kosmale@qt.io>
Pick-to: 6.8
Change-Id: I4ed46f343817932063084642093cac193fd9554f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/corelib/tools/qhash.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 35be65d0f6e..6b11626a4ea 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -1388,6 +1388,9 @@ private: template <typename K> using if_heterogeneously_seachable = QHashPrivate::if_heterogeneously_seachable_with<Key, K>; + template <typename K> + using if_key_constructible_from = std::enable_if_t<std::is_constructible_v<Key, K>, bool>; + public: template <typename K, if_heterogeneously_seachable<K> = true> bool remove(const K &key) @@ -1425,7 +1428,7 @@ public: else return defaultValue; } - template <typename K, if_heterogeneously_seachable<K> = true> + template <typename K, if_heterogeneously_seachable<K> = true, if_key_constructible_from<K> = true> T &operator[](const K &key) { return operatorIndexImpl(key); @@ -2400,6 +2403,9 @@ private: template <typename K> using if_heterogeneously_seachable = QHashPrivate::if_heterogeneously_seachable_with<Key, K>; + template <typename K> + using if_key_constructible_from = std::enable_if_t<std::is_constructible_v<Key, K>, bool>; + public: template <typename K, if_heterogeneously_seachable<K> = true> qsizetype remove(const K &key) @@ -2434,7 +2440,7 @@ public: else return defaultValue; } - template <typename K, if_heterogeneously_seachable<K> = true> + template <typename K, if_heterogeneously_seachable<K> = true, if_key_constructible_from<K> = true> T &operator[](const K &key) { return operatorIndexImpl(key); |
