c++11 - Can I move the contents of one vector to the end of another? -


i want following (a , b both vector<my_moveable_type>):

a.insert(a.end(), b.begin(), b.end()); 

but want operation move b's elements a instead of copying them. have found std::vector::emplace single element, not range.

can done?

you can use std::make_move_iterator, accesses iterator returns rvalue references instead of lvalue references:

a.insert(a.end(), std::make_move_iterator(b.begin()), std::make_move_iterator(b.end())); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -