There is one main.cpp file, in which two global functions getSomeResultFromSomeFunc (), processResult () and the function main () are defined:
std::string getSomeResultFromSomeFunc() { std::string result; if ( cond1 ) { // result = ... } else if ( cond2 ) { // result = ... } return result; } void processResult( const std::string& result ) { ... } int main(void) { std::string myResult = std::move( getSomeResultFromSomeFunc() ); processResult( myResult ); return 0; } Should I use std :: move () when creating a myResult object from another object that is returned by a function? To call the move constructor for the myResult object instead of the copy constructor, since this is a faster way to create an object? Or will the compiler automatically call a relocation constructor instead of a copy constructor, and using std :: move is redundant? And therefore it is enough to write easier?
std::string myResult = getSomeResultFromSomeFunc(); or
std::string myResult( getSomeResultFromSomeFunc() ); For user-defined types, it is easy to check how the compiler behaves, but for types from std, there is no way to check?
Are there differences in the use of std :: move for C ++ 0x and C ++ 11 in this case?
resultwill not be created de facto - immediatelymyResultwill be used. Nomoveis needed in principle. - Harrymoverespectively) in it. - Harry