Re: return from function
On May 5, 8:32 am, "crea" <n...@invalid.com> wrote:
"Kai-Uwe Bux" <jkherci...@gmx.net> wrote in message
typedef std::pair< int, int > int_pair;
int_pair some_function ( some_arg_type some_arg ) {
...
return ( int_pair( first_int, second_int ) );
}
But are you guys using rather references or you normally use "pair" if yo=
u
need to do this? Can pair s type be a reference so that it does not copy
values?
It could, but would the original still exist after the function
has exited? To what would the reference then refer (if it
was initialized with something local (in scope) to the returning
function)...?
Crash boom bang...
I haven't looked at the new standard that much, but perhaps
using move semantics can solve this. I don't think that
it would make any difference for builtin types though.
//Perhaps transfers (or moves) the contents, the only
// problem is that seeing that int has no "underlying"
// data, there may be no gain.
int_pair&& p = some_function();