Back
Close

Modern C++ idoms and recipes

meshell
9,932 views

Keep std::vector sorted

Possible solution

template<typename Cont, typename T>
void insert_sorted(Cont& container, const T& item) {
    const auto insert_pos = std::lower_bound(std::begin(container), std::end(container),item);
    container.insert(insert_pos, item);
};
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants