Probably the most used part of boost for me is boost::shared_ptr.
BOOST_FOREACH makes life worthwhile again.
(Why has nobody mentioned this? The question was asked 8 months ago!)
My faves are, in no particular order:
Boost was a massive help when I wrote my first cross-platform app - without it I really would have struggled.
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<FILE> 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" );
}
Nobody has mentioned Multi-Index Containers so I'll chime in late. It's not that often that you need them, but without boost it is a real pain to create an equivalent data structure, as well as being less efficient. I've been using them a lot recently to create containers that have look up on 2 keys.
I'm surprised that no one has mentioned boost::optional
. I find myself using it more often than any part of Boost except shared_ptr
and scoped_ptr
.
Nobody mentions boost::tuple? For shame!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With