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

Created on 2019-05-31.00:00:00, last changed 2019-07-23.15:26:26.

Messages

Date: 2019-07-23.15:26:26

Proposed resolution:

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-07-23.15:26:26

[ 2019-07 Issue Prioritiztion ]

Priority to 3 after discussion on the reflector.

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
2019-07-23 15:26:26adminsetmessages: + msg10495
2019-06-08 17:20:04adminsetmessages: + msg10426
2019-05-31 00:00:00admincreate