I would like to swap in an std::vector as a function parameter, so that the vector doesn’t have to be copied.
Something like this:
function( std::vector< MyType >().swap( my_vector ) );
Or in my case like this:
std::make_pair( 0, std::vector< MyType >().swap( my_vector ) );
But of course std::vector::swap returns void, not the created vector.
Is there a way to do this?
Use any modern compiler, then you can use
std::move, which takes your vector and returns it as an rvalue:If that’s not available to you, you could try something like this:
Let me know if you have any luck with that.
Or, you can swap the vector directly into the pair after its creation:
Though, I guess this won’t help you if you need the return value of
std::make_pairas an rvalue.