Metatype: Specialize IteratorOwner for vector<bool>
Change-Id: I542af3a77b0a139e137a5a736b74042a8c25eb95 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
This commit is contained in:
parent
4b8a81f525
commit
4e7baaaa91
@ -2405,4 +2405,9 @@ const QMetaObject *metaObjectForQWidget()
|
||||
}
|
||||
}
|
||||
|
||||
namespace QtMetaTypePrivate {
|
||||
bool VectorBoolElements::true_element = true;
|
||||
bool VectorBoolElements::false_element = false;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -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
|
||||
{
|
||||
return *static_cast<const_iterator*>(*it) == *static_cast<const_iterator*>(*other);
|
||||
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<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*>
|
||||
{
|
||||
|
@ -1359,6 +1359,17 @@ void tst_QMetaType::automaticTemplateRegistration()
|
||||
TEST_SEQUENTIAL_CONTAINER(std::vector, int)
|
||||
TEST_SEQUENTIAL_CONTAINER(std::list, int)
|
||||
|
||||
{
|
||||
std::vector<bool> vecbool;
|
||||
vecbool.push_back(true);
|
||||
vecbool.push_back(false);
|
||||
vecbool.push_back(true);
|
||||
QVERIFY(QVariant::fromValue(vecbool).value<std::vector<bool> >().front() == true);
|
||||
QVector<std::vector<bool> > vectorList;
|
||||
vectorList << vecbool;
|
||||
QVERIFY(QVariant::fromValue(vectorList).value<QVector<std::vector<bool> > >().first().front() == true);
|
||||
}
|
||||
|
||||
{
|
||||
QList<QByteArray> bytearrayList;
|
||||
bytearrayList << QByteArray("foo");
|
||||
|
Loading…
Reference in New Issue
Block a user