Use any modern compiler, then you can use std::move , which takes your vector and returns it as rvalue:
function(std::move(my_vector));
If this is not available to you, you can try something like this:
template<typename T> T Move(T & val) { T ret; ret.swap(val); return ret; }
Let me know if you are lucky with this.
Or you can swap the vector directly for a couple after creating it:
std::pair<int, std::vector<MyType> > p; p.second.swap(my_vector);
Although, I think this will not help you if you need to return the value of std::make_pair as rvalue.
source share