Files
cppdraft_translate/cppdraft/alg/fill.md
2025-10-25 03:02:53 +03:00

79 lines
5.0 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[alg.fill]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.7 Mutating sequence operations [[alg.modifying.operations]](alg.modifying.operations#alg.fill)
### 26.7.6 Fill [alg.fill]
[🔗](#lib:fill)
`template<class ForwardIterator, class T = iterator_traits<ForwardIterator>::value_type>
constexpr void fill(ForwardIterator first, ForwardIterator last, const T& value);
template<class ExecutionPolicy, class ForwardIterator,
class T = iterator_traits<ForwardIterator>::value_type>
void fill(ExecutionPolicy&& exec,
ForwardIterator first, ForwardIterator last, const T& value);
template<class OutputIterator, class Size, class T = iterator_traits<OutputIterator>::value_type>
constexpr OutputIterator fill_n(OutputIterator first, Size n, const T& value);
template<class ExecutionPolicy, class ForwardIterator, class Size,
class T = iterator_traits<ForwardIterator>::value_type>
ForwardIterator fill_n(ExecutionPolicy&& exec,
ForwardIterator first, Size n, const T& value);
template<class O, [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<O> S, class T = iter_value_t<O>>
requires [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10Concept output_­iterator[iterator.concept.output]")<O, const T&>
constexpr O ranges::fill(O first, S last, const T& value);
template<class R, class T = range_value_t<R>>
requires [output_range](range.refinements#concept:output_range "25.4.6Other range refinements[range.refinements]")<R, const T&>
constexpr borrowed_iterator_t<R> ranges::fill(R&& r, const T& value);
template<class O, class T = iter_value_t<O>>
requires [output_iterator](iterator.concept.output#concept:output_iterator "24.3.4.10Concept output_­iterator[iterator.concept.output]")<O, const T&>
constexpr O ranges::fill_n(O first, iter_difference_t<O> n, const T& value);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, [sized_sentinel_for](iterator.concept.sizedsentinel#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]")<O> S,
class T = iter_value_t<O>>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, const T&>
O ranges::fill(Ep&& exec, O first, S last, const T& value);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [sized-random-access-range](range.refinements#concept:sized-random-access-range "25.4.6Other range refinements[range.refinements]") R, class T = range_value_t<R>>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<iterator_t<R>, const T&>
borrowed_iterator_t<R> fill(Ep&& exec, R&& r, const T& value);
template<[execution-policy](algorithms.parallel.defns#concept:execution-policy "26.3.1Preamble[algorithms.parallel.defns]") Ep, [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13Concept random_­access_­iterator[iterator.concept.random.access]") O, class T = iter_value_t<O>>
requires [indirectly_writable](iterator.concept.writable#concept:indirectly_writable "24.3.4.3Concept indirectly_­writable[iterator.concept.writable]")<O, const T&>
O ranges::fill_n(Ep&& exec, O first, iter_difference_t<O> n, const T& value);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7432)
Let N be max(0, n) for the fill_n algorithms, andlast - first for the fill algorithms[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7436)
*Mandates*: The expression value is writable ([[iterator.requirements.general]](iterator.requirements.general "24.3.1General")) to the output iterator[.](#2.sentence-1)
The type Size is convertible
to an integral type ([[conv.integral]](conv.integral "7.3.9Integral conversions"), [[class.conv]](class.conv "11.4.8Conversions"))[.](#2.sentence-2)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7443)
*Effects*: Assigns value through all the iterators in the range [first, first + N)[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7448)
*Returns*: first + N[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L7452)
*Complexity*: Exactly N assignments[.](#5.sentence-1)