Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i get started using boost

Tags:

c++

boost

I hear a lot about boost here and I am beginning to think it could help a lot with my software development. More so in concurrency and memory management in my particular case as we have had a lot of bugs in this area.

What are the key language features I need to polish up on to effectively benefit from using boost and to shorten the learning curve? I have seen that function objects are commonly used so I would probably need to polish up on that.

Additionally, are there any tutorials and 101 resources I can quickly look at to just get a feel and understanding on using boost.

I realise there is a lot boost offers and I have to pick the right tools for the right job but any leads will help.

Related

  • How to learn boost (no longer valid; HTTP return status 404)
like image 506
dubnde Avatar asked Mar 28 '09 19:03

dubnde


5 Answers

Boost has an unimaginable number of libraries. Easy ones to get started on are

  • noncopyable
  • array
  • circular_buffer
  • foreach
  • operators (one of my personal favorites)
  • smart_ptr
  • date_time

More advanced ones include

  • lambda
  • bind
  • iostreams
  • serialization
  • threads

Getting used to boost takes time, but I assure you it will make your life much better. Plus, looking at how the boost libraries are coded will help you get better at c++ coding, especially templates.

You mentioned what should you look up before trying boost. I agree that function objects are a great thing to research. Also, make sure to look up about template programming. A common problem to make sure you know is when to use the typename qualifier for dependent types. For the most part, however, the libraries are very well documented, with examples and reference materials.

like image 183
rlbond Avatar answered Nov 13 '22 07:11

rlbond


Learning boost is discussed here. As for language features that are useful? All of them. C++ is a dangerous language to use if you don't know enough of it. RAII, functors/function objects and templates probably cover the most important aspects. Boost is designed similarly to the STL, so knowing your standard library is essential. Boost itself uses a lot of template metaprogramming, but as a library user, you won't often need that (unless you start playing with Boost.MPL)

Bugs related to memory management are a good indicator that it's C++, rather than Boost you need to brush up on. The techniques for handling memory safely are well known, and not specific to Boost. (With the obvious exception of Boost's smart pointers). RAII is probably the most important concept to understand to deal with this kind of issues.

like image 31
jalf Avatar answered Nov 13 '22 07:11

jalf


What are the key language features I need to polish up on to effectively benefit from using boost and to shorten the learning curve?

  • Templates
  • Functors
  • Exceptions
  • STL
    • Iterators
    • Algorithms
    • Containers

... among others.

are there any tutorials and 101 resources I can quickly look at to just get a feel and understanding on using boost.

Boost is well documented. Start here.

There are too many libraries to get lost. I'd say start with something simple, maybe smart pointers or Boost.Test (Unit Test framework) -- which will quickly help you get started. Also, try to think of a problem you cannot solve with the STL easily. Then look up Boost documentation or post here.

If you are comfortable with functional programming look at MPL/Lambda libraries.

like image 4
dirkgently Avatar answered Nov 13 '22 07:11

dirkgently


The first ting IMO are smart pointers. Integration into new code is simple, and usually not a problem for existing code. They make memory management easy, and work for many other ressources, too.

C++ gives you the power to manage your own memory, smart pointers let you (mostly) wing it when you don't need to.

The second would be - as you mentioned - function objects, they close a big gap within C++ that is traditionally solved through inheritance, which is to strong of a coupling in many cases.

I have only little experience with boost outside these two, but most of the remainder is fairly "situational" - you may or may not need it. Get an overview over the libraries, and see what you need.

boost::any and boost::variant are good of you need a variant data type, with two different approaches.

boost::regex if you need some text parsing.

boost::thread and boost::filesystem help you write portable code. If you already have good platform specific libraries, you might not need them - but they are better than API or C++ level in any case.

Maybe you like my introduction to boost smart pointers, and a rather unorthodox use for them.

like image 4
peterchen Avatar answered Nov 13 '22 06:11

peterchen


Try Björn Karlsson's book: Beyond the C++ Standard Library: An Introduction to Boost. Its pretty straightforward and easy to grasp. I read this after I'd finished Scott Meyers three c++ books (effective series).

like image 1
Schildmeijer Avatar answered Nov 13 '22 06:11

Schildmeijer