single_view
should provide empty
Section: 25.6.3.2 [range.single.view] Status: WP Submitter: Hewill Kang Opened: 2023-12-31 Last modified: 2024-04-02
Priority: Not Prioritized
View all other issues in [range.single.view].
View all issues with WP status.
Discussion:
Although single_view::empty
can be synthesized through view_interface
,
it seems more worthwhile to provide a static empty
for it which eliminates the
need to pass in an object parameter, guarantees noexcept
-ness, and is consistent
with the design of empty_view
(demo):
#include <ranges>
auto empty = std::views::empty<int>;
static_assert(noexcept(empty.empty()));
static_assert(noexcept(empty.size()));
auto single = std::views::single(0);
static_assert(noexcept(single.empty())); // fire
static_assert(noexcept(single.size()));
[2024-03-12; Reflector poll]
Set status to Tentatively Ready after six votes in favour during reflector poll.
[Tokyo 2024-03-23; Status changed: Voting → WP.]
Proposed resolution:
This wording is relative to N4971.
Modify 25.6.3.2 [range.single.view] as indicated:
[…]namespace std::ranges { template<move_constructible T> requires is_object_v<T> class single_view : public view_interface<single_view<T>> { […] public: […] constexpr T* begin() noexcept; constexpr const T* begin() const noexcept; constexpr T* end() noexcept; constexpr const T* end() const noexcept; static constexpr bool empty() noexcept; static constexpr size_t size() noexcept; constexpr T* data() noexcept; constexpr const T* data() const noexcept; }; […] }constexpr T* end() noexcept; constexpr const T* end() const noexcept;-5- Effects: Equivalent to:
return data() + 1;
static constexpr bool empty() noexcept;-?- Effects: Equivalent to:
return false;