#include #include #include #include template < typename T > void supprimer(std::list& L, T val) { for(auto it = L.begin(); it != L.end();) { if(*it == val) it = L.erase(it); else ++it; } } template < typename T > void supprimer(std::forward_list& L, T val) { auto prec = L.before_begin(); for(auto it = next(prec); it != L.end();) { if(*it == val) L.erase_after(prec); else ++prec; it = next(prec); } } template < typename T > void supprimer(std::vector& V, T val) { auto i_write = V.begin(); for( auto i_read = V.begin(); i_read != V.end(); ++i_read ) { if(*i_read != val) { *i_write = std::move(*i_read); ++i_write; } } V.erase(i_write,V.end()); } template void display(I first, I last) { while(first != last) { std::cout << *first << " "; ++first; } std::cout << std::endl; } std::vector V { 0, 1, 2, 3, 2, 1, 0, 0, 1, 2 } ; std::list L(V.begin(),V.end()); std::forward_list F(V.begin(),V.end()); display(F.begin(),F.end()); supprimer(F,0); display(F.begin(),F.end()); display(L.begin(),L.end()); supprimer(L,0); display(L.begin(),L.end()); display(V.begin(),V.end()); supprimer(V,0); display(V.begin(),V.end());