C++ Logo

std-discussion

Advanced search

Re: Aggregate initialization with reuse?

From: Bjorn Reese <breese_at_[hidden]>
Date: Sun, 2 Jun 2019 16:28:41 +0200
The question is not about designated initializers, nor did the provided
example use them. The question is about using member variables in
aggregate initialization. Do notice that the example uses "a.x" not
".x".


On 6/2/19 4:24 PM, Timur Doumler via Std-Discussion wrote:
> Note also that C++20 designated initialisers are different from C designated initialisers. In C, the order doesn't matter and also you can mix designated and regular initialisers.
>
> Cheers,
> Timur
>
>> On 2 Jun 2019, at 16:21, Timur Doumler via Std-Discussion <std-discussion_at_[hidden]> wrote:
>>
>> I was assuming this thread was about C++20, where designated initialisers are introduced, and work like I described:
>> wg21.link/p0329
>>
>> If this thread is about C++17, then yes, there are no designated initialisers in C++17.
>>
>> Cheers,
>> Timur
>>
>>> On 2 Jun 2019, at 16:14, Language Lawyer via Std-Discussion <std-discussion_at_[hidden]> wrote:
>>>
>>> There are no designated initializers.
>>>
>>>> On 02/06/2019 17:12, Timur Doumler via Std-Discussion wrote:
>>>> No. According to P0329, you can neither mix designated and regular initialisers, nor can you write designated initialisers in the wrong order compared to their order of declaration in the struct.
>>>> Cheers,
>>>> Timur
>>>>> On 2 Jun 2019, at 15:26, Bjorn Reese via Std-Discussion <std-discussion_at_[hidden]> wrote:
>>>>>
>>>>> Assuming I have an aggregate, is it legal to initialize later member
>>>>> variables with earlier member variables?
>>>>>
>>>>> For instance, is it legal to use a.x in the aggregate initialization
>>>>> below:
>>>>>
>>>>> struct {
>>>>> int x;
>>>>> int y;
>>>>> } a{42, a.x};
>>>>> --
>>>>> Std-Discussion mailing list
>>>>> Std-Discussion_at_[hidden]
>>>>> http://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>>> --
>>> Std-Discussion mailing list
>>> Std-Discussion_at_[hidden]
>>> http://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>>
>> --
>> Std-Discussion mailing list
>> Std-Discussion_at_[hidden]
>> http://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>

Received on 2019-06-02 09:30:29