S
Stefan Ram
I wrote
struct string
{
/* copy constructor */ string( string const & s )
{ ::std::cerr << "string( string const & )\n"; }
/* move constructor */ string( string && ) noexcept
{ ::std::cerr << "string( string && ) noexcept\n"; }
/* additional entries here */ };
and then, later:
string a{ "abc" }; []( string const s )->string{ return s; }( a );
. The statement »[]( string const s )->string{ return s; }( a );« printed
string( string const & )
string( string const & )
. So the implementation is using the copy constructor twice,
and is not using the move constructor, even for the return?
I have expected it to use the copy constructor for parameter
initialization, but the move constructor for returning the
result.
The same with »return ::std::move( s );«.
struct string
{
/* copy constructor */ string( string const & s )
{ ::std::cerr << "string( string const & )\n"; }
/* move constructor */ string( string && ) noexcept
{ ::std::cerr << "string( string && ) noexcept\n"; }
/* additional entries here */ };
and then, later:
string a{ "abc" }; []( string const s )->string{ return s; }( a );
. The statement »[]( string const s )->string{ return s; }( a );« printed
string( string const & )
string( string const & )
. So the implementation is using the copy constructor twice,
and is not using the move constructor, even for the return?
I have expected it to use the copy constructor for parameter
initialization, but the move constructor for returning the
result.
The same with »return ::std::move( s );«.