From 2e07d045ff617173dbbb1382b67f7afe30564699 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 8 Dec 2021 14:18:32 +0100 Subject: [PATCH] tst_containerapisymmetry: test ranged ctors with pure input_iterator types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fails in Qt 6, succeeds in Qt 5.15, therefore needed to add the version check. Pick-to: 6.2 5.15 Task-number: QTBUG-99036 Change-Id: I9da1b2511d844b5fdcb63fdc58c8bc34d0f65736 Reviewed-by: Qt CI Bot Reviewed-by: MÃ¥rten Nordheim --- .../tst_containerapisymmetry.cpp | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp index 3224a8c877..c6090fa671 100644 --- a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp +++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp @@ -38,8 +38,10 @@ #include #include #include // for reference +#include #include #include +#include #include #include #include @@ -49,6 +51,28 @@ # define STDLIB_HAS_UNIFORM_ERASURE #endif +QT_BEGIN_NAMESPACE +std::ostream &operator<<(std::ostream &os, const QChar &c) +{ + Q_ASSERT(c == QLatin1Char{c.toLatin1()}); + return os << c.toLatin1(); +} +std::istream &operator>>(std::istream &os, QChar &c) +{ + char cL1; + os >> cL1; + c = QLatin1Char{cL1}; + return os; +} +QT_END_NAMESPACE + +namespace { +template +struct is_qlist : std::false_type {}; +template +struct is_qlist> : std::true_type {}; +} + struct Movable { explicit Movable(int i = 0) noexcept @@ -70,6 +94,11 @@ struct Movable int i; static int instanceCount; + + friend std::ostream &operator<<(std::ostream &os, const Movable &m) + { return os << m.i; } + friend std::istream &operator>>(std::istream &os, Movable &m) + { return os >> m.i; } }; int Movable::instanceCount = 0; @@ -111,6 +140,11 @@ struct Complex int i; static int instanceCount; + + friend std::ostream &operator<<(std::ostream &os, const Complex &c) + { return os << c.i; } + friend std::istream &operator>>(std::istream &os, Complex &c) + { return os >> c.i; } }; int Complex::instanceCount = 0; @@ -422,12 +456,30 @@ void tst_ContainerApiSymmetry::ranged_ctor_non_associative_impl() const // from itself const Container c4(reference.begin(), reference.end()); + // from stringsteam (= pure input_iterator) + const Container c5 = [&] { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) // QTBUG-99036 + if constexpr (is_qlist::value) { + return c4; + } else +#endif + { + std::stringstream ss; + for (auto &v : values1) + ss << v << ' '; + ss.seekg(0); + return Container(std::istream_iterator{ss}, + std::istream_iterator{}); + } + }(); + QCOMPARE(c1, reference); QCOMPARE(c2a, reference); QCOMPARE(c2b, reference); QCOMPARE(c3a, reference); QCOMPARE(c3b, reference); QCOMPARE(c4, reference); + QCOMPARE(c5, reference); }