diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-06-02 13:33:07 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-06-04 06:32:46 +0000 |
commit | f9fe3330181db7eef7eb8469ca7371517153f66b (patch) | |
tree | e67efdc0da59a3c92f30d3c0214530aaec851f28 | |
parent | 114d00f0430c8a5ef6905931ffaa340bcb54cde6 (diff) |
QVariant: replace fromValue() specializations with if-constexpr
Keeps all the special cases in a central place and will help with
adding an rvalue overload of fromValue() for 6.6.
Change-Id: I14f12bb98a2e2f4edfcec8ce39660643e23c1d07
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | src/corelib/kernel/qvariant.h | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index fe99ad6bdd..ed4978699f 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -563,6 +563,10 @@ public: { if constexpr (std::is_null_pointer_v<T>) return QVariant(QMetaType::fromType<std::nullptr_t>()); + else if constexpr (std::is_same_v<T, QVariant>) + return value; + else if constexpr (std::is_same_v<T, std::monostate>) + return QVariant(); return QVariant(QMetaType::fromType<T>(), std::addressof(value)); } @@ -693,18 +697,6 @@ public: inline const DataPtr &data_ptr() const { return d; } }; -template<> -inline QVariant QVariant::fromValue(const QVariant &value) -{ - return value; -} - -template<> -inline QVariant QVariant::fromValue(const std::monostate &) noexcept -{ - return QVariant(); -} - inline bool QVariant::isValid() const { return d.type().isValid(); |