12

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

2

7 Answers 7

10

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Fantastic. This looks looks gradual and will probably take this approach including all the other suggestions from the answers here. Thanks
7

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, and 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.

1 Comment

I will quote you for C++ is a dangerous language to use if you don't know enough of it, my feelings really resonated with your thoughts. But I don't have enough experience that I can materialize them in words.
4

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.

1 Comment

Thanks. Should clarify I am already confortable with C++ including the use of STL, Excpetions and Templates.
4

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

C++ gives you the power to manage your own memory, and 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.

Comments

1

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

Comments

1

After reading Beyond the C++ Standard Library: An Introduction to Boost, I would recommend casually browsing the documentation on boost.org, just to get an idea of what's available. You can do a deep dive into a specific Boost library when it looks like a good fit for a particular application.

Comments

0

I think shared_ptr should be the easiest place to start.

Start using it in places of simple pointer or auto_ptr data types.

You can also look into weak_ptr.

1 Comment

simply using shared_ptr instead of auto_ptr is not appropriate in all situations. Look up "Ownership Semantics" It is the key to memory management in C++.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.