And I read the SO post somewhere that this [...] matches [...]
They were wrong. They are similar, but not the same.
Using an extended list of commands, you can initialize the return value in place. If you create a temporary, then what you do creates a temporary and then copies it to the return value. Any compiler deserving its salt will be deprived of it, but the copy constructor should be available.
But since the braced-init list initializes the return value in place, you do not need access to the copy constructor.
From the standard, section 6.6.3, p2:
The return statement with the-init-list bandage initializes the object or link that will be returned from the function by initializing-initialization-list (8.5.4) from the specified list of initializers.
Note that "copy-list-initialization" is not like "copy-initialization"; it does not make any copies and therefore does not require an accessible copy constructor. The only difference between copy-list-initialization and direct-list initialization is that the former will throttle explicit constructors.
Nicol Bolas Mar 10 '13 at 22:20 2013-03-10 22:20
source share