diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-09-07 09:57:30 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-09-12 09:12:18 +0200 |
commit | 73fe229eb434236402ec1685b1f17f96417001b9 (patch) | |
tree | bc6bb03553b3bdcdf76f8ef478d532be9471404c /src | |
parent | 89c65bc8f7e4c9ab8198fba08eb1ef6f7f5184d2 (diff) |
QMetaContainer: Add an "input" iterator capability
For completeness' sake we should expose this. The iterators provided by
QIterable and friends will check the category at runtime, and should give
sensible feedback.
Change-Id: I778894f340c862f79a18c6c5607bcbba98dd7598
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qmetacontainer.cpp | 17 | ||||
-rw-r--r-- | src/corelib/kernel/qmetacontainer.h | 10 |
2 files changed, 24 insertions, 3 deletions
diff --git a/src/corelib/kernel/qmetacontainer.cpp b/src/corelib/kernel/qmetacontainer.cpp index 553deffe33..77ac152508 100644 --- a/src/corelib/kernel/qmetacontainer.cpp +++ b/src/corelib/kernel/qmetacontainer.cpp @@ -71,6 +71,23 @@ QT_BEGIN_NAMESPACE */ /*! + Returns \c true if the underlying container provides at least an input + iterator as defined by std::input_iterator_tag, otherwise returns + \c false. Forward, Bi-directional, and random access iterators are + specializations of input iterators. This method will also return + \c true if the container provides one of those. + + QMetaSequence assumes that const and non-const iterators for the same + container have the same iterator traits. + */ +bool QMetaSequence::hasInputIterator() const +{ + if (!d_ptr) + return false; + return d_ptr->iteratorCapabilities & QtMetaContainerPrivate::InputCapability; +} + +/*! Returns \c true if the underlying container provides at least a forward iterator as defined by std::forward_iterator_tag, otherwise returns \c false. Bi-directional iterators and random access iterators are diff --git a/src/corelib/kernel/qmetacontainer.h b/src/corelib/kernel/qmetacontainer.h index 34e99f920d..1e2157951e 100644 --- a/src/corelib/kernel/qmetacontainer.h +++ b/src/corelib/kernel/qmetacontainer.h @@ -50,9 +50,10 @@ QT_BEGIN_NAMESPACE namespace QtMetaContainerPrivate { enum IteratorCapability : quint8 { - ForwardCapability = 1 << 0, - BiDirectionalCapability = 1 << 1, - RandomAccessCapability = 1 << 2, + InputCapability = 1 << 0, + ForwardCapability = 1 << 1, + BiDirectionalCapability = 1 << 2, + RandomAccessCapability = 1 << 3, }; Q_DECLARE_FLAGS(IteratorCapabilities, IteratorCapability) @@ -122,6 +123,8 @@ class QMetaSequenceForContainer { using Tag = typename std::iterator_traits<Iterator>::iterator_category; IteratorCapabilities caps {}; + if constexpr (std::is_base_of_v<std::input_iterator_tag, Tag>) + caps |= InputCapability; if constexpr (std::is_base_of_v<std::forward_iterator_tag, Tag>) caps |= ForwardCapability; if constexpr (std::is_base_of_v<std::bidirectional_iterator_tag, Tag>) @@ -515,6 +518,7 @@ public: return QMetaSequence(QtMetaContainerPrivate::qMetaSequenceInterfaceForContainer<T>()); } + bool hasInputIterator() const; bool hasForwardIterator() const; bool hasBidirectionalIterator() const; bool hasRandomAccessIterator() const; |