This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Tentatively NAD status.
chunk_view::outer-iterator::value_type
should provide empty
Section: 25.7.29.4 [range.chunk.outer.value] Status: Tentatively NAD Submitter: Hewill Kang Opened: 2023-11-05 Last modified: 2024-03-11
Priority: Not Prioritized
View all other issues in [range.chunk.outer.value].
View all issues with Tentatively NAD status.
Discussion:
chunk_view::outer-iterator::value_type
can determine whether it is empty by simply checking whether the
chunk_view
's remainder_
is 0
, which makes it valuable to explicitly provide a
noexcept empty
member.
view_interface::empty
is synthesized only through the size
member when the original
sentinel and iterator type model sized_sentinel_for
, which seems overkill:
#include <cassert> #include <iostream> #include <sstream> #include <ranges> int main() { auto ints = std::istringstream{"1 2 3 4 5 6 7 8 9 10"}; for (auto chunk : std::views::istream<int>(ints) | std::views::chunk(3)) { for (auto elem : chunk) { assert(!chunk.empty()); // no matching function for call to 'empty()' std::cout << elem << " "; } assert(chunk.empty()); // ditto std::cout << "\n"; } }
[2024-03-11; Reflector poll]
Set status to Tentatively NAD after reflector poll in November 2023.
"The example shows you could use it if it existed, but not why that would be useful."
"This is a bad idea - the fact that the chunk 'shrinks' as it is iterated over is an implementation detail and not supposed to be observable."
Proposed resolution:
This wording is relative to N4964.
Modify 25.7.29.4 [range.chunk.outer.value] as indicated:
[…]namespace std::ranges { template<view V> requires input_range<V> struct chunk_view<V>::outer-iterator::value_type : view_interface<value_type> { private: chunk_view* parent_; // exposition only constexpr explicit value_type(chunk_view& parent); // exposition only public: constexpr inner-iterator begin() const noexcept; constexpr default_sentinel_t end() const noexcept; constexpr bool empty() const noexcept; constexpr auto size() const requires sized_sentinel_for<sentinel_t<V>, iterator_t<V>>; }; }constexpr default_sentinel_t end() const noexcept;-3- Returns:
default_sentinel
.constexpr bool empty() const noexcept;-?- Effects: Equivalent to:
return parent_->remainder_ == 0;