I like how you can supply your own destructor for shared_ptr
.
This means, for example, you can use it with FILE*
and get it to close the file for you.
eg
void safeclose(FILE*fp) {
if(fp) {
fclose(fp);
}
}
void some_fn() {
boost::shared_ptr fp( fopen(myfilename, "a+t"), safeclose );
//body of the function, and when ever it exits the file gets closed
fprintf( fp.get(), "a message\n" );
}