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>
Change-Id: I4ed46f343817932063084642093cac193fd9554f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit a338f67dceed61009375a4a90a7fe32a06b443a0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2024-09-06 10:38:44 +02:00 committed by Qt Cherry-pick Bot
parent 3dc6b37bae
commit 799f6bf43f

View File

@ -1380,6 +1380,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)
@ -1417,7 +1420,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);
@ -2389,6 +2392,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)
@ -2423,7 +2429,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);