diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-07-28 14:43:24 +0300 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-08-07 23:09:03 +0300 |
commit | 247ab241c783f776489d8bc348a84cb533079241 (patch) | |
tree | d64ee3dc0ba59d86a6f723e7dea533c7e3b55df9 /tests | |
parent | bf99c4bf553ea750f68745133960084f0b4c0490 (diff) |
QVector/QList/QLinkedList/QVarLengthArray/QSet: add missing deduction guides
Amends 2e1763d83a1dacfc5b747934fb77fa7cec7bfe47.
The new range ctors need deduction guides, since the compiler can't
deduce the value_type from a pair of iterators.
Change-Id: I3ec1e5f91305b317c443b6a70246be416b55bad9
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/tools/qlinkedlist/qlinkedlist.pro | 2 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp | 28 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qlist/qlist.pro | 2 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qlist/tst_qlist.cpp | 28 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qset/qset.pro | 2 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qset/tst_qset.cpp | 28 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qvarlengtharray/qvarlengtharray.pro | 2 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp | 29 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qvector/qvector.pro | 2 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qvector/tst_qvector.cpp | 28 |
10 files changed, 151 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qlinkedlist/qlinkedlist.pro b/tests/auto/corelib/tools/qlinkedlist/qlinkedlist.pro index 378c574eb0..c53d553d6d 100644 --- a/tests/auto/corelib/tools/qlinkedlist/qlinkedlist.pro +++ b/tests/auto/corelib/tools/qlinkedlist/qlinkedlist.pro @@ -1,5 +1,7 @@ CONFIG += testcase TARGET = tst_qlinkedlist QT = core testlib +qtConfig(c++14): CONFIG += c++14 +qtConfig(c++1z): CONFIG += c++1z SOURCES = tst_qlinkedlist.cpp DEFINES -= QT_NO_LINKED_LIST diff --git a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp index deb3b68c5c..df42b5dea9 100644 --- a/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp +++ b/tests/auto/corelib/tools/qlinkedlist/tst_qlinkedlist.cpp @@ -187,6 +187,7 @@ private slots: void countInt() const; void countMovable() const; void countComplex() const; + void cpp17ctad() const; void emptyInt() const; void emptyMovable() const; void emptyComplex() const; @@ -594,6 +595,33 @@ void tst_QLinkedList::countComplex() const QCOMPARE(liveCount, Complex::getLiveCount()); } +void tst_QLinkedList::cpp17ctad() const +{ +#ifdef __cpp_deduction_guides +#define QVERIFY_IS_LIST_OF(obj, Type) \ + QVERIFY2((std::is_same<decltype(obj), QLinkedList<Type>>::value), \ + QMetaType::typeName(qMetaTypeId<decltype(obj)::value_type>())) +#define CHECK(Type, One, Two, Three) \ + do { \ + const Type v[] = {One, Two, Three}; \ + QLinkedList v1 = {One, Two, Three}; \ + QVERIFY_IS_LIST_OF(v1, Type); \ + QLinkedList v2(v1.begin(), v1.end()); \ + QVERIFY_IS_LIST_OF(v2, Type); \ + QLinkedList v3(std::begin(v), std::end(v)); \ + QVERIFY_IS_LIST_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_LIST_OF +#undef CHECK +#else + QSKIP("This test requires C++17 Constructor Template Argument Deduction support enabled in the compiler."); +#endif +} + template<typename T> void tst_QLinkedList::empty() const { diff --git a/tests/auto/corelib/tools/qlist/qlist.pro b/tests/auto/corelib/tools/qlist/qlist.pro index 47f0140abb..118c607880 100644 --- a/tests/auto/corelib/tools/qlist/qlist.pro +++ b/tests/auto/corelib/tools/qlist/qlist.pro @@ -1,4 +1,6 @@ CONFIG += testcase TARGET = tst_qlist QT = core testlib +qtConfig(c++14): CONFIG += c++14 +qtConfig(c++1z): CONFIG += c++1z SOURCES = $$PWD/tst_qlist.cpp diff --git a/tests/auto/corelib/tools/qlist/tst_qlist.cpp b/tests/auto/corelib/tools/qlist/tst_qlist.cpp index 5a485e88d2..cc9a3a16d1 100644 --- a/tests/auto/corelib/tools/qlist/tst_qlist.cpp +++ b/tests/auto/corelib/tools/qlist/tst_qlist.cpp @@ -310,6 +310,7 @@ private slots: void lastComplex() const; void constFirst() const; void constLast() const; + void cpp17ctad() const; void beginOptimal() const; void beginMovable() const; void beginComplex() const; @@ -864,6 +865,33 @@ void tst_QList::constLast() const QVERIFY(listCopy.isSharedWith(list)); } +void tst_QList::cpp17ctad() const +{ +#ifdef __cpp_deduction_guides +#define QVERIFY_IS_LIST_OF(obj, Type) \ + QVERIFY2((std::is_same<decltype(obj), QList<Type>>::value), \ + QMetaType::typeName(qMetaTypeId<decltype(obj)::value_type>())) +#define CHECK(Type, One, Two, Three) \ + do { \ + const Type v[] = {One, Two, Three}; \ + QList v1 = {One, Two, Three}; \ + QVERIFY_IS_LIST_OF(v1, Type); \ + QList v2(v1.begin(), v1.end()); \ + QVERIFY_IS_LIST_OF(v2, Type); \ + QList v3(std::begin(v), std::end(v)); \ + QVERIFY_IS_LIST_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_LIST_OF +#undef CHECK +#else + QSKIP("This test requires C++17 Constructor Template Argument Deduction support enabled in the compiler."); +#endif +} + template<typename T> void tst_QList::last() const { diff --git a/tests/auto/corelib/tools/qset/qset.pro b/tests/auto/corelib/tools/qset/qset.pro index d0c6337147..3ae4bc4805 100644 --- a/tests/auto/corelib/tools/qset/qset.pro +++ b/tests/auto/corelib/tools/qset/qset.pro @@ -1,6 +1,8 @@ CONFIG += testcase TARGET = tst_qset QT = core testlib +qtConfig(c++14): CONFIG += c++14 +qtConfig(c++1z): CONFIG += c++1z SOURCES = tst_qset.cpp DEFINES -= QT_NO_JAVA_STYLE_ITERATORS diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp index 31b4c0449e..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; diff --git a/tests/auto/corelib/tools/qvarlengtharray/qvarlengtharray.pro b/tests/auto/corelib/tools/qvarlengtharray/qvarlengtharray.pro index 108fb33db5..14b2bc213b 100644 --- a/tests/auto/corelib/tools/qvarlengtharray/qvarlengtharray.pro +++ b/tests/auto/corelib/tools/qvarlengtharray/qvarlengtharray.pro @@ -1,4 +1,6 @@ CONFIG += testcase TARGET = tst_qvarlengtharray QT = core testlib +qtConfig(c++14): CONFIG += c++14 +qtConfig(c++1z): CONFIG += c++1z SOURCES = tst_qvarlengtharray.cpp diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp index 3d90644aa3..a1d0100f96 100644 --- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp +++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp @@ -44,6 +44,7 @@ private slots: void realloc(); void reverseIterators(); void count(); + void cpp17ctad(); void first(); void last(); void squeeze(); @@ -717,6 +718,34 @@ void tst_QVarLengthArray::count() } } +void tst_QVarLengthArray::cpp17ctad() +{ +#ifdef __cpp_deduction_guides +#define QVERIFY_IS_VLA_OF(obj, Type) \ + QVERIFY2((std::is_same<decltype(obj), QVarLengthArray<Type>>::value), \ + QMetaType::typeName(qMetaTypeId<decltype(obj)::value_type>())) +#define CHECK(Type, One, Two, Three) \ + do { \ + const Type v[] = {One, Two, Three}; \ + QVarLengthArray v1 = {One, Two, Three}; \ + QVERIFY_IS_VLA_OF(v1, Type); \ + QVarLengthArray v2(v1.begin(), v1.end()); \ + QVERIFY_IS_VLA_OF(v2, Type); \ + QVarLengthArray v3(std::begin(v), std::end(v)); \ + QVERIFY_IS_VLA_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_VLA_OF +#undef CHECK +#else + QSKIP("This test requires C++17 Constructor Template Argument Deduction support enabled in the compiler."); +#endif + +} + void tst_QVarLengthArray::first() { // append some items, make sure it stays sane diff --git a/tests/auto/corelib/tools/qvector/qvector.pro b/tests/auto/corelib/tools/qvector/qvector.pro index b9a4ae747b..689d9b87a2 100644 --- a/tests/auto/corelib/tools/qvector/qvector.pro +++ b/tests/auto/corelib/tools/qvector/qvector.pro @@ -1,5 +1,7 @@ CONFIG += testcase qtConfig(c++11): CONFIG += c++11 +qtConfig(c++14): CONFIG += c++14 +qtConfig(c++1z): CONFIG += c++1z TARGET = tst_qvector QT = core testlib SOURCES = $$PWD/tst_qvector.cpp diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp index 05b5579d64..08d5a8cd50 100644 --- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp +++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp @@ -230,6 +230,7 @@ private slots: void countInt() const; void countMovable() const; void countCustom() const; + void cpp17ctad() const; void data() const; void emptyInt() const; void emptyMovable() const; @@ -914,6 +915,33 @@ void tst_QVector::countCustom() const QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } +void tst_QVector::cpp17ctad() const +{ +#ifdef __cpp_deduction_guides +#define QVERIFY_IS_VECTOR_OF(obj, Type) \ + QVERIFY2((std::is_same<decltype(obj), QVector<Type>>::value), \ + QMetaType::typeName(qMetaTypeId<decltype(obj)::value_type>())) +#define CHECK(Type, One, Two, Three) \ + do { \ + const Type v[] = {One, Two, Three}; \ + QVector v1 = {One, Two, Three}; \ + QVERIFY_IS_VECTOR_OF(v1, Type); \ + QVector v2(v1.begin(), v1.end()); \ + QVERIFY_IS_VECTOR_OF(v2, Type); \ + QVector v3(std::begin(v), std::end(v)); \ + QVERIFY_IS_VECTOR_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_VECTOR_OF +#undef CHECK +#else + QSKIP("This test requires C++17 Constructor Template Argument Deduction support enabled in the compiler."); +#endif +} + void tst_QVector::data() const { QVector<int> myvec; |