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

### 3772. `repeat_view`'s piecewise constructor is missing Postconditions

Section: 26.6.5.2 [range.repeat.view] Status: New Submitter: Hewill Kang Opened: 2022-09-12 Last modified: 2022-09-25

Priority: 2

View all other issues in [range.repeat.view].

View all issues with New status.

Discussion:

The first two value-bound pair constructors of `repeat_view` have the Preconditions that the integer-like object `bound` must be non-negative. However, the piecewise constructor does not mention the valid values for `bound_args`. It would be nice to add a Postconditions that the initialized `bound_` must be greater than or equal to `0` here.

[2022-09-23; Reflector poll]

Set priority to 2 after reflector poll.

This is trying to state a requirement on users, but that's not what Postconditions: means. Should be something more like:
Precondition: If `Bound` is not `unreachable_sentinel_t`, the `bound_` ≥ 0 after its initialization from `bound_args`.

Previous resolution [SUPERSEDED]:

> This wording is relative to N4917.

> 1. Modify 26.6.5.2 [range.repeat.view] as shown:

>    >     template<class... WArgs, class... BoundArgs>
>    >       requires constructible_from<W, WArgs...> &&
>    >                constructible_from<Bound, BoundArgs...>
>    >     constexpr explicit repeat_view(piecewise_construct_t,
>    >       tuple<Wargs...> value_args, tuple<BoundArgs...> bound_args = tuple<>{});

>    > > -5- Effects: Initializes `value_` with arguments of types `WArgs...` obtained by forwarding the elements of `value_args` and initializes `bound_` with arguments of types `BoundArgs...` obtained by forwarding the elements of `bound_args`. (Here, forwarding an element `x` of type `U` within a tuple object means calling `std::forward<U>(x)`.)

>    > > -?- Postconditions: If `Bound` is not `unreachable_sentinel_t`, `bound_` ≥ 0.

[2022-09-23; Jonathan provides improved wording]

Proposed resolution:

This wording is relative to N4917.

1. Modify 26.6.5.2 [range.repeat.view] as shown:

   >     template<class... WArgs, class... BoundArgs>
   >       requires constructible_from<W, WArgs...> &&
   >                constructible_from<Bound, BoundArgs...>
   >     constexpr explicit repeat_view(piecewise_construct_t,
   >       tuple<Wargs...> value_args, tuple<BoundArgs...> bound_args = tuple<>{});

   > > -?- Preconditions: `Bound` is `unreachable_sentinel_t`, or the initialization of `bound_` yields a non-negative value.

   > > -5- Effects: Initializes `value_` with arguments of types `WArgs...` obtained by forwarding the elements of `value_args` and initializes `bound_` with arguments of types `BoundArgs...` obtained by forwarding the elements of `bound_args`. (Here, forwarding an element `x` of type `U` within a tuple object means calling `std::forward<U>(x)`.)