开发者

Multiset to vector, C++

开发者 https://www.devze.com 2023-03-02 15:30 出处:网络
How to copy last k items from std::multiset in rev开发者_开发技巧ersed order to std::vector as fast as possible?If you use the non-standard copy_n (you can easily roll your own), you can just do this:

How to copy last k items from std::multiset in rev开发者_开发技巧ersed order to std::vector as fast as possible?


If you use the non-standard copy_n (you can easily roll your own), you can just do this:

std::copy_n(your_multiset.rbegin(), k, std::back_inserter(your_vector));

copy_n is part of C++1x, so there this solution is fully standard. If you want speed, it might be faster to reserve space in the vector in advance to save reallocations.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号