Beyond the C++ Standard Library: An Introduction to Boost

I just finished reading Beyond the C++ Standard Library: An Introduction to Boost. A really interesting read. Some of the more interesting things that I picked up:

  • boost::shared_ptr – like auto_ptr on steroids, a very nice reference-counted smart pointer. Not only can it clean up memory allocated with new, but you can pass in a custom deleter and thus use it to clean up anything, such as close a file or database connection, etc. The book also covers shared_array, intrusive_ptr, weak_ptr, scoped_ptr, and scoped_array
  • boost::numeric_cast can warn you when you’re casting a number to a smaller number type that will truncate.
  • boost::lexical_cast can convert back and forth between strings and numbers, thereby accomplishing in one concise line, conversions that I normally do with a few lines of stringstream code.
  • boost::regex can do all kinds of interesting things with regular expressions.
  • boost::any is an interesting variant type that allows storing several types of values, but is type-safe in the sense that it makes the caller specify the correct type in order to gain access.
  • boost::tuple is a logical extension of std::pair and allows a nice way to get multiple return values from a function:
    boost::tuple gcd_lcm(int val1, int val2);
    ...
    boost::tie(gcd, lcm) = gcd_lcm(15, 20);
    
  • boost::signal is an interesting “signals and slots” (or “publish and subscribe” or callbacks) implementation.

Leave a Reply

Your email address will not be published.