Hi,
Edit:
anarelle I didn't see your post while I was typing my reply.
This might seem a bit complicated and way over the top, but here goes.
C++ also has move semantics, which use rvalue references.
Basically, when one returns a container from a function, the compiler "moves" the container being returned. The basic concept of that is: The memory address of the old value now belongs to the new variable. The old variable may or may not still exist.
The container must have move semantics enabled, which means it must have a move constructor. I am fairly sure that all the STL containers have them.
The move constructor uses rvlaues denoted by 2 & after the variable name (as in
variable&&
) . There are different types of rvalues, in the case of returning from a function, it is an xvalue. The 'x' means "expiring" which is easy to remember because the returned value is going out of scope.
When passing a container
to a function, then it is as
Norm Gunderson, unless (as I understand it) the argument is a call to
std::move
(not sure why one would do that), so it's best to pass containers by reference. So this includes
std::string
and any class that you might invent yourself.
I hope my simplistic explanation has of been some help. The topic is not simple IMO, so it is probably best to read up about it.