Course info
Jun 11, 2014
2h 56m

This course gives an overview of Boost: a set of C++ libraries designed to cover some of the functionality that's missing from the STL. This course covers the libraries that are used for storing optional values (Boost.Optional), reading program options (Boost.ProgramOptions), storing any type of value in a generic container (Boost.Any), implementing the signal/slot paradigm (a.k.a Observer pattern) (Boost.Signals2), working with the local file system (Boost.Filesystem), and also covers an assortment of smaller libraries including Boost string algorithms, Boost.Bimap, and Boost.Units.

About the author
About the author

Dmitri is a developer, speaker, podcaster, technical evangelist and wannabe quant.

More from the author
ReSharper Fundamentals
2h 54m
Apr 28, 2017
More courses by Dmitri Nesteruk
Section Introduction Transcripts
Section Introduction Transcripts

Getting Started With Boost
Welcome. My name is Dmitri and I'm happy to welcome you to this course on the Boost C++ Libraries. Before we begin, let's talk about what Boost actually is. Boost is a set of free, open-source C++ libraries and these libraries cover different types of functionality that isn't included in the C++ Standard Template Library. Now the range of features that's covered is huge and it includes anything from image processing support to support for threading, inter-process communication, as well as lots of little utility features that might come in handy in your development process. Now Boost is portable, meaning that it will work on the vast majority of C++ compilers. It doesn't require any modern C++ features so it will work on all C++ compilers if you choose to use one. Now Boost can and sometimes does have issues with certain C++ compilers so it's worth checking the documentation just in case. Boost is widely used, both in applications as well as forming a foundation of other libraries such as my favorite library, QuantLib, and in fact, Boost is so successful that some of the features of Boost keep migrating into C++ itself, which is a testament to how good the library is. Don't worry though, the parts that do migrate also stay in Boost so your code won't break in future releases, but keep in mind, however, that the implementation that gets taken into C++ may sometimes differ from what's being included in Boost itself.

Welcome. In this module we're going to talk about Boost. Any, which is essentially a library that allows storing an object of any type in a container. So in other programming languages such as C# or Java for example, well, the developers are lucky. They have a root object type and it's actually possible to cast a primitive value such as the literal 123 into that type, into an object and this is called boxing and it's something can be subsequently used to have a collection of these objects where the actual type can be checked in runtime and in C++ unfortunately we don't have this functionality. We don't have this out of the box and we do have discriminated unions, but the problem with those is that these are limited to just the few types that you define in the union and it only accepts primitive types so discriminated unions are of limited use and Boost. Any is essentially a container that can store values of practically any type and the values are stored as they are. So if you feed a number like 42, it gets stored as an int. It doesn't get converted into a textual representation or anything like that. The fidelity of the type is preserved and the end result is that it can be used in collections and in fact if you look around Boost, well for example, if you look in the program options library you will see that a variables map type is actually using Boost. Any as a way of storing values of any type. And of course, Boost. Any provides an API for getting the values and checking the value is in fact of a particular type.

Welcome. In this module we're going to look at Boost. FileSystem, which as you may have guessed, is a library for various file system related operations. So what kind of things do we want to do with the file system? Well, first of all the overriding goal is that we want to work with a file system in a portable manner regardless of which operating system we're actually using and some of the typical tasks that we might be interested in are for example, determine if a file or directory exists, or measuring the file size or determining whether the file is read-only for example, and of course, we want to somehow navigate the directory hierarchies, sort of move up and down or get a directory listing for example, and the library generally consists of two things so first of all we have objects, which represent the file structure elements. The most central object is called path and then we have utility functions, so for example the function exists basically checks whether a file or a directory at a particular path does in fact exist. Now in Boost. FileSystem the error handling is done via C++ exceptions and this library is actually in the process of migrating to the STL so you should check your C++ STL because you might have those elements already in there in the namespace, std::tr2.

Odds and Ends
Alright, so we're nearing the end of our course and in this module I just want to cover a few things that I personally find useful in Boost. They don't constitute large libraries that I could give a whole module to, but we're going to look at few smaller libraries. So what are we going to cover? Well I want to talk a little bit about string operations because as somebody coming from a. NET background, I find the STL lacking in quite many aspects of string manipulations so some of the things we're going to look at are the Tokenizer library, the LexicalCast, and some string algorithms. We're also going to look at bimap, which is a bidirectional map and then I want to talk about the support for units of measure, which is also provided by a library in Boost.