Date: Thu, 13 Aug 2020 00:01:08 +0200
On 12/08/2020 21.37, Jens Gustedt via Liaison wrote:
> Since it seems that designated initializers are new in C++20, had that
> particular property much been used before?
Assuming you refer to defined ordering in something like
int x = 0;
int a[] = { x++, x++, x++ }; // 3 elements with values 0, 1, 2
(with no designated initializers): yes, C++ code relies on it.
The guaranteed ordering is used heavily when handling variadic
templates iteratively (instead of recursively), for example
template<class ... T>
void g(T...args)
{
int dummy[] = { (f(args), 0) ... };
}
Here, we want to call f for each argument, in order.
Jens
> Since it seems that designated initializers are new in C++20, had that
> particular property much been used before?
Assuming you refer to defined ordering in something like
int x = 0;
int a[] = { x++, x++, x++ }; // 3 elements with values 0, 1, 2
(with no designated initializers): yes, C++ code relies on it.
The guaranteed ordering is used heavily when handling variadic
templates iteratively (instead of recursively), for example
template<class ... T>
void g(T...args)
{
int dummy[] = { (f(args), 0) ... };
}
Here, we want to call f for each argument, in order.
Jens
Received on 2020-08-12 17:04:35