Title
single_view should provide empty
Status
wp
Section
[range.single.view]
Submitter
Hewill Kang

Created on 2023-12-31.00:00:00 last changed 3 weeks ago

Messages

Date: 2024-04-02.10:29:12

Proposed resolution:

This wording is relative to N4971.

  1. Modify [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;

Date: 2024-04-02.10:29:12

[ Tokyo 2024-03-23; Status changed: Voting → WP. ]

Date: 2024-03-15.00:00:00

[ 2024-03-12; Reflector poll ]

Set status to Tentatively Ready after six votes in favour during reflector poll.

Date: 2023-12-31.00:00:00

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()));
History
Date User Action Args
2024-04-02 10:29:12adminsetmessages: + msg14043
2024-04-02 10:29:12adminsetstatus: voting -> wp
2024-03-18 09:32:04adminsetstatus: ready -> voting
2024-03-12 00:57:03adminsetmessages: + msg13994
2024-03-12 00:57:03adminsetstatus: new -> ready
2024-01-13 17:19:15adminsetmessages: + msg13914
2023-12-31 00:00:00admincreate