summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-05-10 18:29:02 +0200
committerMarc Mutz <marc.mutz@qt.io>2023-05-16 20:09:40 +0200
commit7ca633d9a82f90e5bba5e12ba923bfb0a257af63 (patch)
treef424d1ff5d7d9fc4e6404e58e4e4376a67c592a7
parentbbbe5f45c4d354ef977d4e09459ef5ae4d6db0da (diff)
downloadqtbase-7ca633d9a82f90e5bba5e12ba923bfb0a257af63.tar.gz
QArrayDataPointer: add a C++20 ranges-style optional projection to assign()
This will be useful for implementing QString::assign(), which otherwise has the problem that it's d_ptr is based on char16_t, but it's assign() is supposed to be able to deal with iterators whose value_type returns QChar. Task-number: QTBUG-106198 Change-Id: I87882bf749b4e21b7b32391167962d3e6bae9983 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r--src/corelib/tools/qarraydatapointer.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h
index b458dc3626..3839baefcf 100644
--- a/src/corelib/tools/qarraydatapointer.h
+++ b/src/corelib/tools/qarraydatapointer.h
@@ -7,6 +7,8 @@
#include <QtCore/qarraydataops.h>
#include <QtCore/qcontainertools_impl.h>
+#include <QtCore/q20functional.h>
+
QT_BEGIN_NAMESPACE
template <class T>
@@ -305,8 +307,8 @@ public:
this->ptr = res;
}
- template <typename InputIterator>
- void assign(InputIterator first, InputIterator last)
+ template <typename InputIterator, typename Projection = q20::identity>
+ void assign(InputIterator first, InputIterator last, Projection proj = {})
{
// This function only provides the basic exception guarantee.
constexpr bool IsFwdIt = std::is_convertible_v<
@@ -340,12 +342,12 @@ public:
break;
} else {
do {
- (*this)->emplace(size, *first);
+ (*this)->emplace(size, proj(*first));
} while (++first != last);
return; // size() is already correct (and dst invalidated)!
}
}
- *dst = *first; // overwrite existing element
+ *dst = proj(*first); // overwrite existing element
++dst;
++first;
}