A universal solution for almost any container, such as std :: list, std :: map, boost :: multi_index. You must check the size of your card.
template<class It> It myadvance(It it, size_t n) { std::advance(it, n); return it; } template<class Cont> void resize_container(Cont & cont, size_t n) { cont.erase(myadvance(cont.begin(), std::min(n, cont.size())), cont.end()); }
Alexey Malistov
source share