diff options
Diffstat (limited to 'tests/auto/corelib/tools/qset/tst_qset.cpp')
-rw-r--r-- | tests/auto/corelib/tools/qset/tst_qset.cpp | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp index 0b60350380..8a545712a2 100644 --- a/tests/auto/corelib/tools/qset/tst_qset.cpp +++ b/tests/auto/corelib/tools/qset/tst_qset.cpp @@ -54,6 +54,7 @@ private slots: void detach(); void isDetached(); void clear(); + void cpp17ctad(); void remove(); void contains(); void containsSet(); @@ -325,6 +326,33 @@ void tst_QSet::clear() QVERIFY(set2.size() == 0); } +void tst_QSet::cpp17ctad() +{ +#ifdef __cpp_deduction_guides +#define QVERIFY_IS_SET_OF(obj, Type) \ + QVERIFY2((std::is_same<decltype(obj), QSet<Type>>::value), \ + QMetaType::typeName(qMetaTypeId<decltype(obj)::value_type>())) +#define CHECK(Type, One, Two, Three) \ + do { \ + const Type v[] = {One, Two, Three}; \ + QSet v1 = {One, Two, Three}; \ + QVERIFY_IS_SET_OF(v1, Type); \ + QSet v2(v1.begin(), v1.end()); \ + QVERIFY_IS_SET_OF(v2, Type); \ + QSet v3(std::begin(v), std::end(v)); \ + QVERIFY_IS_SET_OF(v3, Type); \ + } while (false) \ + /*end*/ + CHECK(int, 1, 2, 3); + CHECK(double, 1.0, 2.0, 3.0); + CHECK(QString, QStringLiteral("one"), QStringLiteral("two"), QStringLiteral("three")); +#undef QVERIFY_IS_SET_OF +#undef CHECK +#else + QSKIP("This test requires C++17 Constructor Template Argument Deduction support enabled in the compiler."); +#endif +} + void tst_QSet::remove() { QSet<QString> set1; @@ -955,7 +983,6 @@ void tst_QSet::makeSureTheComfortFunctionsCompile() void tst_QSet::initializerList() { -#ifdef Q_COMPILER_INITIALIZER_LISTS QSet<int> set = {1, 1, 2, 3, 4, 5}; QCOMPARE(set.count(), 5); QVERIFY(set.contains(1)); @@ -976,9 +1003,6 @@ void tst_QSet::initializerList() QSet<int> set3{{}, {}, {}}; QVERIFY(!set3.isEmpty()); -#else - QSKIP("Compiler doesn't support initializer lists"); -#endif } void tst_QSet::qhash() @@ -1011,15 +1035,7 @@ void tst_QSet::qhash() // check that sets of sets work: // { -#ifdef Q_COMPILER_INITIALIZER_LISTS QSet<QSet<int> > intSetSet = { { 0, 1, 2 }, { 0, 1 }, { 1, 2 } }; -#else - QSet<QSet<int> > intSetSet; - QSet<int> intSet01, intSet12; - intSet01 << 0 << 1; - intSet12 << 1 << 2; - intSetSet << intSet01 << intSet12 << (intSet01|intSet12); -#endif QCOMPARE(intSetSet.size(), 3); } } |