On 11/2/2015 3:24 PM, Stefan Ram wrote:
> How could the following two forms of initialization be
> described?
>
> They are both initializations involving a kind of
> »brace-initializer list«, yet they might possibly be
> different.
>
> #include <initializer_list>
> #include <utility>
> #include <string>
>
> int main()
> { { ::std::pair< int, ::std::string >p{ 7, "alpha" }; }
> { ::std::pair< int, ::std::string >p( { 7, "alpha" } ); }}
>
> Are there any examples where one of these can be used for a
> local variable definition, but not the other?
>
I think a good guideline for test code is to make it as simple as
possible, but, as reportedly Albert Einstein remarked, no more.
struct S
{
#ifdef NOCOPY
S( S const& ) = delete;
#endif
S( int, char const* ) {}
};
int main()
{
{ S p{ 7, "alpha" }; }
{ S p( { 7, "alpha" } ); }
}
So, both examples are formally direct initialization, but the second one
involves a temporary instance of the class and is /effectively/ a copy
initialization.
The language has become, well not yet too complex for me, but almost.
Cheers & hth.,
- Alf