diff options
author | Stephen Kelly <stephen.kelly@kdab.com> | 2014-04-29 15:31:51 +0200 |
---|---|---|
committer | Ismo Haataja <ismo.haataja@digia.com> | 2014-06-16 07:44:02 +0200 |
commit | 4e7baaaa91ce663b0b5c315e5b049d1574aef73f (patch) | |
tree | 6012cff006d772adfaa8681bad4871817f141b74 /src | |
parent | 4b8a81f52516d59801637520533cb298aeb802e7 (diff) |
Metatype: Specialize IteratorOwner for vector<bool>
Change-Id: I542af3a77b0a139e137a5a736b74042a8c25eb95
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qmetatype.cpp | 5 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatype.h | 33 |
2 files changed, 35 insertions, 3 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index f74c592e8c..251e4614ab 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -2405,4 +2405,9 @@ const QMetaObject *metaObjectForQWidget() } } +namespace QtMetaTypePrivate { +bool VectorBoolElements::true_element = true; +bool VectorBoolElements::false_element = false; +} + QT_END_NAMESPACE diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 9c61a67962..cecfce65ce 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -782,7 +782,7 @@ private: }; template<typename const_iterator> -struct IteratorOwner +struct IteratorOwnerCommon { static void assign(void **ptr, const_iterator iterator) { @@ -804,6 +804,15 @@ struct IteratorOwner delete static_cast<const_iterator*>(*ptr); } + static bool equal(void * const *it, void * const *other) + { + return *static_cast<const_iterator*>(*it) == *static_cast<const_iterator*>(*other); + } +}; + +template<typename const_iterator> +struct IteratorOwner : IteratorOwnerCommon<const_iterator> +{ static const void *getData(void * const *iterator) { return &**static_cast<const_iterator*>(*iterator); @@ -813,12 +822,30 @@ struct IteratorOwner { return &*it; } +}; - static bool equal(void * const *it, void * const *other) +struct Q_CORE_EXPORT VectorBoolElements +{ + static bool true_element; + static bool false_element; +}; + +template<> +struct IteratorOwner<std::vector<bool>::const_iterator> : IteratorOwnerCommon<std::vector<bool>::const_iterator> +{ +public: + static const void *getData(void * const *iterator) { - return *static_cast<const_iterator*>(*it) == *static_cast<const_iterator*>(*other); + return **static_cast<std::vector<bool>::const_iterator*>(*iterator) ? + &VectorBoolElements::true_element : &VectorBoolElements::false_element; + } + + static const void *getData(const std::vector<bool>::const_iterator& it) + { + return *it ? &VectorBoolElements::true_element : &VectorBoolElements::false_element; } }; + template<typename value_type> struct IteratorOwner<const value_type*> { |