views::adjacent<0> should be prohibited
Hewill Kang

Created on 2022-07-13.00:00:00 last changed 4 weeks ago


Date: 2022-07-16.12:18:12

Proposed resolution:

This wording is relative to N4910.

  1. Modify [range.adjacent.overview] as indicated:

    -2- The name views::adjacent<N> denotes a range adaptor object ([range.adaptor.object]). Given a subexpression E and a constant expression N, the expression views::adjacent<N>(E) is expression-equivalent to:

    1. (2.1) — ((void)E, auto(views::empty<tuple<>>))Iif N is equal to 0, views::adjacent<N>(E) is ill-formed.

    2. (2.2) — Ootherwise, adjacent_view<views::all_t<decltype((E))>, N>(E).

  2. Modify [range.adjacent.transform.overview] as indicated:

    -2- The name views::adjacent_transform<N> denotes a range adaptor object ([range.adaptor.object]). Given subexpressions E and F and a constant expression N:

    1. (2.1) — If N is equal to 0, views::adjacent_transform<N>(E, F) is ill-formedexpression-equivalent to ((void)E, views::zip_transform(F)), except that the evaluations of E and F are indeterminately sequenced.

    2. (2.2) — Otherwise, the expression views::adjacent_transform<N>(E, F) is expression-equivalent to adjacent_transform_view<views::all_t<decltype((E))>, decay_t<decltype((F))>, N>(E, F).

Date: 2022-07-13.00:00:00

views::adjacent is very similar to views::slide, except that the window size N is given at compile time.

Since the case where N is 0 does not make sense for slide_view, LWG 3711 and LWG 3712 added preconditions to the constructor and removed the default constructor, respectively.

But for views::adjacent, we can still specify N to be 0. According to the description of [range.adjacent.overview], it will return views::empty<tuple<>> as in the case of views::zip applied to an empty pack. And for views::adjacent_transform<0>(E, F), it will return views::zip_transform(F) and eventually return empty_view for some type.

This doesn't seem reasonable to me. The reason why views::zip can return views::empty<tuple<>> is that the parameter pack can indeed be empty, so this still makes some sense. However, there is no meaningful sense for the word "adjacent" when N is 0.

I don't see any observable value in allowing views::adjacent<0>, we should disable it for consistency with views::slide.

Date User Action Args
2022-07-16 12:18:12adminsetmessages: + msg12584
2022-07-13 00:00:00admincreate