C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::ranges::equal(v, {1,2,3,4,5})

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Thu, 26 Jan 2023 02:35:58 +0100
Hi,

On 25/01/2023 14:15, Paolo Di Giglio via Std-Proposals wrote:
> The only drawback I can see here is that the compiler won't deduce the
> type of the array from an empty initializer list, i.e. this won't
> compile:
>
> std::vector<int> v;
> assert(std::ranges::equal(v, {}));
>
> This is because the size of an array must be greater than 0.
>
> The code above wouldn't compile with the overload proposed by Arthur
> either, as the compiler doesn't know how to deduce V2. In that case,
> however, you could default V2 to the value type of range r1.
>
> What are your thoughts on this?

Finding a way to make {} work would be very nice; indeed one can't have
arrays of length 0, but can have initializer_lists of length 0.

As far as codegen is concerned, I think that today using
initializer_list or using an array would generate identical code, but if
P2752 is adopted an initializer_list should become a strictly better
alternative...?

My 2 c,
-- 
Giuseppe D'Angelo

Received on 2023-01-26 01:36:02