pt({{1,2}});
>> int main() {
>> for (auto p:pt) std::cout<> }
>>
>> gives:
>> 1
>> 2
>
> my guess is the above pt declarator is roughly equivalent to
> pt(vector(initializer_list(initializer_list(1,2)))) --
> which just happens to give you an expected result. I think it is
> undefined or implementation-specific what default copy constructor does
> on initializer_list because the data members of it are not defined by
> the standard.
This seems wrong to me. Please note I am not saying it IS wrong,
only that it seems to me to be wrong. More specifically I don't
think undefined behavior plays a role. I tried reading the
Standard to verify that but found it impenetrable in this area.
Can someone help find the relevant passages (and an accompanying
explanation would also be appreciated)?
>> here. Just as I expected.
>>
>>> { /* something */ } introduces a braced initialization list.
>>>
>>> { { /* something */ } } introduces a braced initialization list with
>>> one value.
>>
>> But didn't we need to use two braces for container intialization?
>
> for vector, because there is constructor with count and value, you
> need something like = { 1, 2}; (note =) for {1,2} to be interpreted as
> initializer_list; for vector you should be able to initialize
> with {"One", "Two"} directly.
I'm pretty sure what you say about vector isn't right. A
declaration like
vector foo { 10, 1 };
gives a vector of length 2, not a vector of length 10. If the
braces were parentheses
vector bas ( 10, 1 );
we would get a vector of length 10, using the ( count, value )
constructor.
Disclaimer: the comments above are based solely on experimental
results, not on understanding what the Standard says about it.