I\'m looking for practical and educational samples of C++ / STL code fitting in few lines. My actual favorites are:
Empty a vector freeing its reserved memory:<
// std::back_inserter usage ( std::inserter for map )
std::copy( source.begin(), source.end(), std::back_inserter( container ) );
-
// mem_fun and bind usage (but boost better)
std::some_algorithm(..., std::mem_fun( func ) );
not so useful, but powerful:
check is container sorted
std::adjacent_find( container.begin(), container.end(), greater() ) == container.end()
also examples mentioned by you and dirkgently.