[C++17]
I have a class:
class A
{
int a;
int b;
public:
A(int a, int b) : a{ a }, b{ b } { }
};
and two functions:
int get_a() { return 1; }
int get_b() { return 2; }
Now I construct an object:
A a{ get_a(), get_b() };
The question: is it guaranteed for this case that the order of function evaluation is always get_a and then get_b?
>Solution :
This is called list-initialization.
From cppreference:
Every initializer clause is sequenced before any initializer clause that follows it in the braced-init-list. This is in contrast with the arguments of a function call expression, which are unsequenced(until C++17) indeterminately sequenced(since C++17).
Therefore, then answer is yes, get_a() will always be sequenced before get_b().