diff options
Diffstat (limited to 'src/corelib/kernel/qvariant.h')
-rw-r--r-- | src/corelib/kernel/qvariant.h | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index a2c5711993..fe1ef1bdfc 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -53,6 +53,10 @@ #include <QtCore/qbytearraylist.h> #endif +#if QT_HAS_INCLUDE(<variant>) && __cplusplus >= 201703L +#include <variant> +#endif + QT_BEGIN_NAMESPACE @@ -284,14 +288,14 @@ class Q_CORE_EXPORT QVariant void detach(); inline bool isDetached() const; - int toInt(bool *ok = Q_NULLPTR) const; - uint toUInt(bool *ok = Q_NULLPTR) const; - qlonglong toLongLong(bool *ok = Q_NULLPTR) const; - qulonglong toULongLong(bool *ok = Q_NULLPTR) const; + int toInt(bool *ok = nullptr) const; + uint toUInt(bool *ok = nullptr) const; + qlonglong toLongLong(bool *ok = nullptr) const; + qulonglong toULongLong(bool *ok = nullptr) const; bool toBool() const; - double toDouble(bool *ok = Q_NULLPTR) const; - float toFloat(bool *ok = Q_NULLPTR) const; - qreal toReal(bool *ok = Q_NULLPTR) const; + double toDouble(bool *ok = nullptr) const; + float toFloat(bool *ok = nullptr) const; + qreal toReal(bool *ok = nullptr) const; QByteArray toByteArray() const; QBitArray toBitArray() const; QString toString() const; @@ -355,12 +359,21 @@ class Q_CORE_EXPORT QVariant static inline QVariant fromValue(const T &value) { return qVariantFromValue(value); } +#if QT_HAS_INCLUDE(<variant>) && __cplusplus >= 201703L + template<typename... Types> + static inline QVariant fromStdVariant(const std::variant<Types...> &value) + { + if (value.valueless_by_exception()) + return QVariant(); + return std::visit([](const auto &arg) { return fromValue(arg); }, value); + } +#endif + template<typename T> bool canConvert() const { return canConvert(qMetaTypeId<T>()); } public: -#ifndef Q_QDOC struct PrivateShared { inline PrivateShared(void *v) : ptr(v), ref(1) { } @@ -370,7 +383,7 @@ class Q_CORE_EXPORT QVariant struct Private { inline Private() Q_DECL_NOTHROW : type(Invalid), is_shared(false), is_null(true) - { data.ptr = Q_NULLPTR; } + { data.ptr = nullptr; } // Internal constructor for initialized variants. explicit inline Private(uint variantType) Q_DECL_NOTHROW @@ -431,7 +444,6 @@ class Q_CORE_EXPORT QVariant f_canConvert canConvert; f_debugStream debugStream; }; -#endif inline bool operator==(const QVariant &v) const { return cmp(v); } @@ -505,6 +517,11 @@ inline QVariant qVariantFromValue(const T &t) template <> inline QVariant qVariantFromValue(const QVariant &t) { return t; } +#if QT_HAS_INCLUDE(<variant>) && __cplusplus >= 201703L +template <> +inline QVariant qVariantFromValue(const std::monostate &) { return QVariant(); } +#endif + template <typename T> inline void qVariantSetValue(QVariant &v, const T &t) { |