From fd2685c2f0a219c091e028a98ba6cdd154986fec Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 7 Oct 2022 16:50:42 +0200 Subject: Short live q20::fill{,_n}! MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/corelib/global/q20algorithm.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/corelib/global') 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 +constexpr void +fill(ForwardIterator first, ForwardIterator last, const Value &value) +{ + while (first != last) { + *first = value; + ++first; + } +} + +template +constexpr OutputIterator +fill_n(OutputIterator first, Size n, const Value &value) +{ + while (n > Size{0}) { + *first = value; + ++first; + --n; + } + return first; +} + template > constexpr ForwardIterator is_sorted_until(ForwardIterator first, ForwardIterator last, BinaryPredicate p = {}) -- cgit v1.2.3