Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most used parts of Boost [closed]

Tags:

c++

boost

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:

  • regex
  • filesystem
  • thread
  • lexical_cast
  • program_options (just brilliant!)
  • test (for all my unit testing needs).
  • String algorithms
  • String tokenizer
  • format (type-safe printf style string formatting)
  • smart ptrs

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!