diff --git a/src/corelib/tools/qcontainertools_impl.h b/src/corelib/tools/qcontainertools_impl.h index 998bc292d4e..57c9c298356 100644 --- a/src/corelib/tools/qcontainertools_impl.h +++ b/src/corelib/tools/qcontainertools_impl.h @@ -299,8 +299,8 @@ using KeyAndValueTest = decltype( template using FirstAndSecondTest = decltype( - std::declval()->first, - std::declval()->second + (*std::declval()).first, + (*std::declval()).second ); template diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 9cc6fbf30bc..198622a05cc 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -894,8 +894,11 @@ public: : QHash() { QtPrivate::reserveIfForwardIterator(this, f, l); - for (; f != l; ++f) - insert(f->first, f->second); + for (; f != l; ++f) { + auto &&e = *f; + using V = decltype(e); + insert(std::forward(e).first, std::forward(e).second); + } } #endif void swap(QHash &other) noexcept { qt_ptr_swap(d, other.d); } @@ -1463,8 +1466,11 @@ public: QMultiHash(InputIterator f, InputIterator l) { QtPrivate::reserveIfForwardIterator(this, f, l); - for (; f != l; ++f) - insert(f->first, f->second); + for (; f != l; ++f) { + auto &&e = *f; + using V = decltype(e); + insert(std::forward(e).first, std::forward(e).second); + } } #endif QMultiHash(const QMultiHash &other) noexcept diff --git a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp index 8cb494f94b2..beefa2c8a9a 100644 --- a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp +++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp @@ -16,6 +16,9 @@ #include #include #include +#ifdef __cpp_lib_ranges +#include +#endif #include #include #include @@ -737,6 +740,20 @@ void tst_ContainerApiSymmetry::ranged_ctor_associative_impl() const QCOMPARE(c3a, reference); QCOMPARE(c3b, reference); QCOMPARE(c4, reference); + +#ifdef __cpp_lib_ranges + { + auto view1 = values1 | std::views::transform(std::identity{}); + Container c5(std::ranges::begin(view1), + std::ranges::end(view1)); + QCOMPARE(c5, reference); + + auto view2 = values1 | std::views::filter([](auto &&){ return true; }); + Container c6(std::ranges::begin(view2), + std::ranges::end(view2)); + QCOMPARE(c6, reference); + } +#endif } template