diff options
author | Marc Mutz <marc.mutz@qt.io> | 2021-12-08 14:18:32 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2021-12-09 22:49:45 +0100 |
commit | 2e07d045ff617173dbbb1382b67f7afe30564699 (patch) | |
tree | 910dda477b31410a4e88b97fad13b4c2e1f7d773 /tests/auto/corelib/tools | |
parent | b34be3868bd0933813f02c6a0fcbb5afd18b4105 (diff) |
tst_containerapisymmetry: test ranged ctors with pure input_iterator types
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 <qt_ci_bot@qt-project.org>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r-- | tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
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 <algorithm> #include <functional> #include <vector> // for reference +#include <iostream> #include <list> #include <set> +#include <sstream> #include <map> #include <forward_list> #include <unordered_set> @@ -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 <typename T> +struct is_qlist : std::false_type {}; +template <typename T> +struct is_qlist<QList<T>> : 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<Container>::value) { + return c4; + } else +#endif + { + std::stringstream ss; + for (auto &v : values1) + ss << v << ' '; + ss.seekg(0); + return Container(std::istream_iterator<V>{ss}, + std::istream_iterator<V>{}); + } + }(); + QCOMPARE(c1, reference); QCOMPARE(c2a, reference); QCOMPARE(c2b, reference); QCOMPARE(c3a, reference); QCOMPARE(c3b, reference); QCOMPARE(c4, reference); + QCOMPARE(c5, reference); } |