os_release |
Deletes a container of heap-based objects.
Calls operator delete
on every item in the container. Assumes each item is a pointer to a heap-based
object. If more than one item points to the same heap-based object, an error
will probably occur.
#include <ospace/helper/helpalgo.h>
template< class Container >
void os_release( Container& c )
#include <iostream>
#include <vector>
#include <ospace/helper.h>
class X
{
public:
X( int i_ ) : i( i_ ) {}
~X() { cout << "Delete X( " << i << " )\n"; }
int i;
};
ostream&
operator<<( ostream& stream_, const X& x_ )
{
return stream_ << "X( " << x_.i << " )";
}
void
main()
{
vector< X* > v;
v.push_back( new X ( 2 ) );
v.push_back( new X ( 1 ) );
v.push_back( new X ( 4 ) );
for ( vector< X* >::iterator i = v.begin(); i != v.end(); ++i )
cout << *( *i ) << "\n";
os_release( v ); // Delete all heap-based objects in container.
}
}
X(2)
X(1)
X(4)
Delete X(2)
Delete X(1)
Delete X(4)
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.