C++ Logo


Advanced search

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

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Thu, 26 Jan 2023 08:26:42 +0000
On 26 January 2023 01:35:58 GMT, Giuseppe D'Angelo via Std-Proposals <std-proposals_at_[hidden]> wrote:
>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...?

For ranges::equal it seems to be better. For ranges::copy I would allow moving from the source argument, if it's an initializer list. An rvalue reference to an array allows that. The empty list can be handled with an additional overload that takes an empty aggregate.

>My 2 c,


Received on 2023-01-26 08:26:51