C++ Logo

std-proposals

Advanced search

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

From: Zhihao Yuan <zy_at_[hidden]>
Date: Fri, 27 Jan 2023 03:09:30 +0000
On Wednesday, January 25th, 2023 at 5:35 PM, Giuseppe D'Angelo via Std-Proposals <std-proposals_at_[hidden]> wrote:

> 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...?
>


I think it's possible to extend the proposed
semantics to more initializer lists, especially
the P'[N] form supported by [temp.deduct.call].
This case is even less likely to be observed,
because P2752R0's change is visible to
std::initializer_list<T> variables (lvalue),
while in the array's case, the majority of the
people would be using array variables rather
than references to const arrays:

  auto const& r = {3, 5}; // auto is deduced to std::initializer_list
  int r[] = {3, 5}; // lvalue, distinct as is
  const int (&r)[] = {3, 5}; // who write this?

--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
_______________________________________________

Received on 2023-01-27 03:09:54