C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Should `std::array<T, 0>` be `view`?

From: Hewill Kang <hewillk_at_[hidden]>
Date: Fri, 24 May 2024 01:31:46 +0800
>
> This also gets into like... well should array<T, 1> be a view? single is a
> view.


Yap, that's an interesting question. This is why I *only* touched on
`array<T, 0>` as it is absolutely O(1) copyable for `array<T, 0>`.

Hewill

Barry Revzin <barry.revzin_at_[hidden]> 於 2024年5月24日 週五 上午1:25寫道:

>
>
> On Thu, May 23, 2024, 11:39 AM Hewill Kang via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>> The standard specifies a legal case for `std::array` where `N` is `0`. It
>> seems to me that `array<T, 0>` always meets the semantic requirements of
>> `ranges::view`.
>> I'm wondering if there is value in making it a `view` since it behaves
>> very similarly to `views::empty<T>`? For example:
>>
>> template<class T>
>> constexpr bool ranges::enable_view<array<T, 0>> = true;
>> template<class T>
>> constexpr bool ranges::enable_borrowed_range<array<T, 0>> = true;
>>
>> Is this reasonable or is this just a bad idea?
>>
>> Hewill
>>
>
> This also gets into like... well should array<T, 1> be a view? single is a
> view.
>
> And then array<T, 2> is like concat with two singles, and that is a view.
> etc.
>
> Plus what does O(1) copyable even mean on a type that doesn't have
> variable size? Is array<T, N> always O(1) copyable?
>
> Barry
>
>>

Received on 2024-05-23 17:31:59