From d0c4d18b01279869123a36bdbbd65571a6745fc7 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 7 Oct 2020 15:32:38 +0200 Subject: Core: Make the metacontainer interfaces constexpr Change-Id: Ib8e486a855673b191a9854e1c4d62614a2b87e72 Reviewed-by: Fabian Kosmale --- src/corelib/kernel/qmetacontainer.h | 56 +++++++++++++++---------------------- 1 file changed, 23 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/corelib/kernel/qmetacontainer.h b/src/corelib/kernel/qmetacontainer.h index 4bce731d8a..4459319279 100644 --- a/src/corelib/kernel/qmetacontainer.h +++ b/src/corelib/kernel/qmetacontainer.h @@ -110,7 +110,7 @@ public: QMetaContainerInterface() = default; template - QMetaContainerInterface(const MetaContainer &) + constexpr QMetaContainerInterface(const MetaContainer &) : iteratorCapabilities(MetaContainer::getIteratorCapabilities()) , sizeFn(MetaContainer::getSizeFn()) , clearFn(MetaContainer::getClearFn()) @@ -163,7 +163,7 @@ public: QMetaSequenceInterface() = default; template - QMetaSequenceInterface(const MetaSequence &m) + constexpr QMetaSequenceInterface(const MetaSequence &m) : QMetaContainerInterface(m) , valueMetaType(MetaSequence::getValueMetaType()) , addRemoveCapabilities(MetaSequence::getAddRemoveCapabilities()) @@ -220,7 +220,7 @@ public: QMetaAssociationInterface() = default; template - QMetaAssociationInterface(const MetaAssociation &m) + constexpr QMetaAssociationInterface(const MetaAssociation &m) : QMetaContainerInterface(m) , keyMetaType(MetaAssociation::getKeyMetaType()) , mappedMetaType(MetaAssociation::getMappedMetaType()) @@ -687,9 +687,6 @@ class QMetaSequenceForContainer : public QMetaContainerForContainer return nullptr; } } - -public: - static QMetaSequenceInterface metaSequence; }; template @@ -917,31 +914,8 @@ class QMetaAssociationForContainer : public QMetaContainerForContainer return QMetaContainerForContainer::template getEraseAtIteratorFn< QMetaAssociationInterface::EraseKeyAtIteratorFn>(); } - -public: - static QMetaAssociationInterface metaAssociation; }; -template -QMetaSequenceInterface QMetaSequenceForContainer::metaSequence - = QMetaSequenceInterface(QMetaSequenceForContainer()); - -template -QMetaAssociationInterface QMetaAssociationForContainer::metaAssociation - = QMetaAssociationInterface(QMetaAssociationForContainer()); - -template -constexpr QMetaSequenceInterface *qMetaSequenceInterfaceForContainer() -{ - return &QMetaSequenceForContainer::metaSequence; -} - -template -constexpr QMetaAssociationInterface *qMetaAssociationInterfaceForContainer() -{ - return &QMetaAssociationForContainer::metaAssociation; -} - } // namespace QtMetaContainerPrivate class Q_CORE_EXPORT QMetaContainer @@ -987,12 +961,12 @@ class Q_CORE_EXPORT QMetaSequence : public QMetaContainer { public: QMetaSequence() = default; - explicit QMetaSequence(QtMetaContainerPrivate::QMetaSequenceInterface *d) : QMetaContainer(d) {} + explicit QMetaSequence(const QtMetaContainerPrivate::QMetaSequenceInterface *d) : QMetaContainer(d) {} template static constexpr QMetaSequence fromContainer() { - return QMetaSequence(QtMetaContainerPrivate::qMetaSequenceInterfaceForContainer()); + return QMetaSequence(&MetaSequence::value); } QMetaType valueMetaType() const; @@ -1047,6 +1021,14 @@ public: } private: + template + struct MetaSequence + { + static constexpr const QtMetaContainerPrivate::QMetaSequenceInterface value + = QtMetaContainerPrivate::QMetaSequenceInterface( + QtMetaContainerPrivate::QMetaSequenceForContainer()); + }; + const QtMetaContainerPrivate::QMetaSequenceInterface *d() const { return static_cast(d_ptr); @@ -1057,12 +1039,12 @@ class Q_CORE_EXPORT QMetaAssociation : public QMetaContainer { public: QMetaAssociation() = default; - explicit QMetaAssociation(QtMetaContainerPrivate::QMetaAssociationInterface *d) : QMetaContainer(d) {} + explicit QMetaAssociation(const QtMetaContainerPrivate::QMetaAssociationInterface *d) : QMetaContainer(d) {} template static constexpr QMetaAssociation fromContainer() { - return QMetaAssociation(QtMetaContainerPrivate::qMetaAssociationInterfaceForContainer()); + return QMetaAssociation(&MetaAssociation::value); } QMetaType keyMetaType() const; @@ -1233,6 +1215,14 @@ public: } private: + template + struct MetaAssociation + { + static constexpr const QtMetaContainerPrivate::QMetaAssociationInterface value + = QtMetaContainerPrivate::QMetaAssociationInterface( + QtMetaContainerPrivate::QMetaAssociationForContainer()); + }; + const QtMetaContainerPrivate::QMetaAssociationInterface *d() const { return static_cast(d_ptr); -- cgit v1.2.3