Title
for_each_n and copy_n missing requirements for Size
Status
resolved
Section
[alg.foreach][alg.copy]
Submitter
Jonathan Wakely

Created on 2019-05-31.00:00:00 last changed 49 months ago

Messages

Date: 2020-11-09.22:09:58

Proposed resolution:

Resolved by P1718R2

Date: 2020-11-09.00:00:00

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

Date: 2020-05-15.00:00:00

[ 2020-05-01; Reflector discussions ]

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

Date: 2020-05-01.17:34:40

[ 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 [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- RequiresExpects: The type Size is convertible to integral type ([conv.integral], [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- RequiresExpects: The type Size is convertible to integral type ([conv.integral], [class.conv]). n >= 0.

    […]

  2. Modify [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 ([conv.integral], [class.conv]).

    […]

Date: 2019-05-31.00:00:00

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.

History
Date User Action Args
2020-11-09 22:09:58adminsetmessages: + msg11601
2020-05-01 17:34:40adminsetmessages: + msg11246
2020-05-01 17:34:40adminsetstatus: new -> resolved
2019-07-23 15:26:26adminsetmessages: + msg10495
2019-06-08 17:20:04adminsetmessages: + msg10426
2019-05-31 00:00:00admincreate