Date
2022-06-10.00:00:00
Message id
12494

Content

Both chunk_view and slide_view have a precondition that N must be positive, but they are still default_initializable when the underlying range is default_initializable, which makes the member variable n_ initialized with an invalid value 0 when they are default-constructed, which produces the following unexpected result:

#include <ranges>

using V = std::ranges::iota_view<int, int>;
static_assert(std::ranges::slide_view<V>().empty()); // fails
static_assert(std::ranges::chunk_view<V>().empty()); // division by zero is not a constant expression

Although we could provide a default positive value for n_, I think a more appropriate solution would be to not provide the default constructor, since default-constructed values for integer types will never be valid.