Post by Paul LicameliI removed all the unnecessary moves in returns that I could.
But there were places where unique_ptr<Base> needed to be returned (such
as when Base is Track), but the expression returned had type
unique_ptr<Derived> (such as WaveTrack). Then I could not remove
std::move, at least with the Mac compiler.
I am not sure whether the standard says this should work, but standard
compliance is lacking on this compiler, or whether there is something in
the standard justifiying this. Whatever the case, I could not remove all
std::move in return statements.
thanks for the update. Unfortunately it looks like the standard says that
std::move is needed in the return statement if the types aren't the same.
Maybe they'll change the standard one day to cover the
unique_ptr<Base/Derived> case.
See for example:
http://en.cppreference.com/w/cpp/language/copy_elision
Here's the relevant section:
- If a function returns a class type by value, and the return statement
<http://en.cppreference.com/w/cpp/language/return>'s expression is the
name of a non-volatile object with automatic storage duration, which isn't
the function parameter, or a catch clause parameter, and which has the same
type (ignoring top-level cv-qualification
<http://en.cppreference.com/w/cpp/language/cv>) as the return type of
the function, then copy/move is omitted. When that local object is
constructed, it is constructed directly in the storage where the function's
return value would otherwise be moved or copied to. This variant of copy
elision is known as NRVO, "named return value optimization".
David.
Post by Paul LicameliPRL
Post by Paul LicameliAha, that document is edited by Stroustrup himself, and should repay study.
I will remove the unnecessary moves.
PRL
Post by David Baileshttp://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-move
Based on these guidelines, std::move does not need to be used for local
variables in return statements, but it's used several times in the Audacity
code.
David.
------------------------------------------------------------
------------------
_______________________________________________
audacity-devel mailing list
https://lists.sourceforge.net/lists/listinfo/audacity-devel
------------------------------------------------------------
------------------
_______________________________________________
audacity-devel mailing list
https://lists.sourceforge.net/lists/listinfo/audacity-devel