This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Resolved status.

### 3213. `for_each_n` and `copy_n` missing requirements for `Size`

Section: 27.6.5 [alg.foreach], 27.7.1 [alg.copy] Status: Resolved Submitter: Jonathan Wakely Opened: 2019-05-31 Last modified: 2020-11-09

Priority: 3

View all other issues in [alg.foreach].

View all issues with Resolved status.

Discussion:

`search_n` and `fill_n` and `generate_n` require that "The type `Size` shall be convertible to integral type", but `for_each_n` and `copy_n` have no requirements on `Size`. Presumably it should be convertible to an integral type.

[2019-07 Issue Prioritization]

Priority to 3 after discussion on the reflector.

Previous resolution [SUPERSEDED]:

> This wording is relative to N4810.

> > [Drafting note: Clause [algorithms] has not yet gone through a "Mandating" cleanup of our new wording style for requirements expressed in Requires and Expects elements. The below wording changes perform this fix for the touched paragraphs and also replaces here Requires by Expects to prevent papers that address such wording changes to keep tracking of additional wording changes caused by proposed wording of issues.]

> 1. Modify 27.6.5 [alg.foreach] as indicated:

>    >     template<class InputIterator, class Size, class Function>
>    >       constexpr InputIterator for_each_n(InputIterator first, Size n, Function f);

>    > > -16- Requires: shall satisfy the Cpp17MoveConstructible requirements […]

>    > > -17- Requires Expects: The type `Size` is convertible to integral type (7.3.9 [conv.integral], 11.4.8 [class.conv]). `n >= 0`.

>    > > […]

>    >     template<class ExecutionPolicy, class ForwardIterator, class Size, class Function>
>    >       ForwardIterator for_each_n(ExecutionPolicy&& exec, ForwardIterator first, Size n,
>    >                                  Function f);

>    > > -21- Requires: shall satisfy the Cpp17CopyConstructible requirements […]

>    > > -22- Requires Expects: The type `Size` is convertible to integral type (7.3.9 [conv.integral], 11.4.8 [class.conv]). `n >= 0`.

>    > > […]

> 2. Modify 27.7.1 [alg.copy] as indicated:

>    >     template<class InputIterator, class Size, class OutputIterator>
>    >       constexpr OutputIterator copy_n(InputIterator first, Size n,
>    >                                       OutputIterator result);
>    >     template<class ExecutionPolicy, class ForwardIterator1, class Size, class ForwardIterator2>
>    >       ForwardIterator2 copy_n(ExecutionPolicy&& exec,
>    >                               ForwardIterator1 first, Size n,
>    >                               ForwardIterator2 result);
>    >     template<InputIterator I, WeaklyIncrementable O>
>    >       requires IndirectlyCopyable<I, O>
>    >       constexpr ranges::copy_n_result<I, O>
>    >         ranges::copy_n(I first, iter_difference_t<I> n, O result);

>    > > -10- Let `M` be `max(n, 0)`.

>    > > -?- Expects: The type `Size` is convertible to integral type (7.3.9 [conv.integral], 11.4.8 [class.conv]).

>    > > […]

[2020-05-01; Reflector discussions]

There was consensus that this issue has been resolved by P1718R2, voted in in Belfast 2019.

[2020-11-09 Resolved for C++20. Status changed: Tentatively Resolved → Resolved.]

Proposed resolution:

Resolved by P1718R2