summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-10-07 16:50:42 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-10-11 21:17:17 +0000
commitfd2685c2f0a219c091e028a98ba6cdd154986fec (patch)
treea376fcb4b978420f11cb4c66c532566a8005fd52 /src/corelib/global
parente1d21fe813c4c9c3f53e59c08190f80b38e385da (diff)
Short live q20::fill{,_n}!
It just adds constexpr to it (we're ignoring the range version). Apply it to QStaticByteArrayMatcher, where it replaces rather lengthy initialization code. Pick-to: 6.4 Change-Id: I1d60216fb04c94fa66fce5cc01313b3e9ba856ac Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/q20algorithm.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/corelib/global/q20algorithm.h b/src/corelib/global/q20algorithm.h
index 1d2e0117f4..69dc2d2446 100644
--- a/src/corelib/global/q20algorithm.h
+++ b/src/corelib/global/q20algorithm.h
@@ -32,6 +32,8 @@ namespace q20 {
using std::copy;
using std::copy_if;
using std::copy_n;
+using std::fill;
+using std::fill_n;
using std::is_sorted_until;
using std::is_sorted;
using std::transform;
@@ -75,6 +77,28 @@ copy_n(InputIterator first, Size n, OutputIterator dest)
return dest;
}
+template <typename ForwardIterator, typename Value>
+constexpr void
+fill(ForwardIterator first, ForwardIterator last, const Value &value)
+{
+ while (first != last) {
+ *first = value;
+ ++first;
+ }
+}
+
+template <typename OutputIterator, typename Size, typename Value>
+constexpr OutputIterator
+fill_n(OutputIterator first, Size n, const Value &value)
+{
+ while (n > Size{0}) {
+ *first = value;
+ ++first;
+ --n;
+ }
+ return first;
+}
+
template <typename ForwardIterator, typename BinaryPredicate = std::less<>>
constexpr ForwardIterator
is_sorted_until(ForwardIterator first, ForwardIterator last, BinaryPredicate p = {})