
Daniel Frey <daniel.frey@aixigo.de> writes:
Hi,
I just wrote a small helper function to clear a container. Well, OK, we already have that, do we? For a container 'cont':
cont.clear();
But this doesn't neccessarily free the memory allocated. The "usual" workaround is:
Cont().swap( cont );
But Cont (the type of the container) is sometimes rather large and the code doesn't communicate well what I intended.
I thus wrote the following small helper:
template< typename T > void reset( T& t ) { T().swap( t ); }
Would this make a good addition to boost.utility? Any comments welcome...
Not unless you make it generic: template< typename T > void reset( T& t ) { using std::swap; T x; swap(x, t); } -- Dave Abrahams Boost Consulting http://www.boost-consulting.com