This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++23 status.
chunk_view and slide_view should not be default_initializableSection: 25.7.29.2 [range.chunk.view.input], 25.7.29.6 [range.chunk.view.fwd], 25.7.30.2 [range.slide.view] Status: C++23 Submitter: Hewill Kang Opened: 2022-06-10 Last modified: 2023-11-22
Priority: Not Prioritized
View all other issues in [range.chunk.view.input].
View all issues with C++23 status.
Discussion:
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:
#includeusing V = std::ranges::iota_view ; static_assert(std::ranges::slide_view ().empty()); // fails static_assert(std::ranges::chunk_view ().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.
[2022-06-21; Reflector poll]
Set status to Tentatively Ready after six votes in favour during reflector poll.
[2022-07-15; LWG telecon: move to Ready]
[2022-07-25 Approved at July 2022 virtual plenary. Status changed: Ready → WP.]
Proposed resolution:
This wording is relative to N4910.
Modify 25.7.29.2 [range.chunk.view.input] as indicated:
namespace std::ranges {
[…]
template
requires input_range
class chunk_view : public view_interface> {
V base_ = V(); // exposition only
range_difference_t n_ = 0; // exposition only
range_difference_t remainder_ = 0; // exposition only
[…]
public:
chunk_view() requires default_initializable = default;
constexpr explicit chunk_view(V base, range_difference_t n);
[…]
};
[…]
}
Modify 25.7.29.6 [range.chunk.view.fwd] as indicated:
namespace std::ranges {
template
requires forward_range
class chunk_view : public view_interface> {
V base_ = V(); // exposition only
range_difference_t n_ = 0; // exposition only
[…]
public:
chunk_view() requires default_initializable = default;
constexpr explicit chunk_view(V base, range_difference_t n);
[…]
};
}
Modify 25.7.30.2 [range.slide.view] as indicated:
namespace std::ranges {
[…]
template
requires view
class slide_view : public view_interface> {
V base_ = V(); // exposition only
range_difference_t n_ = 0; // exposition only
[…]
public:
slide_view() requires default_initializable = default;
constexpr explicit slide_view(V base, range_difference_t n);
[…]
};
[…]
}