C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Compact Initialization Syntax

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 08 Jun 2025 17:39:21 -0300
On Sunday, 8 June 2025 17:24:20 Brasilia Standard Time Jason McKesson via Std-
Proposals wrote:
> Does a fairly rare circumstance *need* to be "concise"? We don't
> commonly create 4 variables of the same type in the middle of a
> function, and they *certainly* shouldn't be named short things like
> `a` or `d1`.
>
> So do we need shorthand syntax for what ought to be a fairly rare
> circumstance? After all, people have to learn what this means, and if
> they don't see it very often, that makes it much more surprising when
> it shows up.

And it is not far enough from the equivalent:
  float a1, b1, c1, d1;
  a1 = b1 = c1 = d1 = 0.1f;

How would this work for non-trivial types? Would they call the copy
constructor on a1 or would they call the same initialisation constructor?

And if it is the same initialisation constructor, what happens if the called
initialiser expression is not trivial?
int number() { static int i; return ++i; }

  int{number()} i1, i2, i3, i4;

Are they all the same value or are they distinct values?

These two questions alone where it's ambiguous what's happening would probably
be a showstopper.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Platform & System Engineering

Received on 2025-06-08 20:39:26