Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22233

Copy elision possible if returning parameter?

$
0
0

Consider a function that takes an object by value, performs some operations on it and return that object, for example:

std::string MyToUpper (std::string s){      std::transform(s.begin(), s.end(), s.begin(), std::toupper);      return s;}

Now you call this function with a temporary:

std::string Myupperstring = MyToUpper("text");

Conceptually there is no copy needed. Are modern Compilers able to elide all copies in this case? If not, are there only moves? What about this case:

std::string Mylowerstring("text");std::string Myupperstring = MyToUpper(std::move(Mylowerstring));

Viewing all articles
Browse latest Browse all 22233

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>