What is Boost?
Boost is one of the most highly regarded, expert designed and peer-reviewed set of C++ libraries which implements many generic and specialized algorithms such as maths routines, meta-programming, MPI, state machines, parsers and tokenizers.
Why use Boost?
When programming in C++, boost provides several class templates and helper objects that provide readily available solutions for developers. Some of the benefits of using boost include:
- Peer reviewed code
- Efficient implementations of most algorithms
- Avoids re-writing already existing solutions to problems developers are trying to solve (don't re-invent the wheel)
- Get started quickly solving the problem related to their domain using efficient code.
- Unit tested code that has been used in many different production environments.
- Reduce long-term maintenance costs: the developers trying to debug your code 5 years later don't need to understand how you implemented quicksort - if you've used boost you need not rewrite quicksort and they already understand what the sorting algorithm in the library does.
Boost libraries have long been considered best-in-class implementations. Ten boost libraries have already made their way into the official C++11 standards while others are under consideration for the next iteration of the standards update, i.e. C++17.
A few relevant libraries from a machine learning perspective are listed here:
- Accumulators
- Algorithm
- Compute
- Container
- Coroutine
- Filesystem
- Fusion
- Geometry
- GIL (Generic Image Library)
- Boost Graph Library
- Interprocess
- Math Toolkit
- Lockfree
- Maths/Statistical Distributions
- MPI
- OdeInt (solve initial value problems in ordinary differential equations)
- Process
- QVM (Quaternions, Vectors, Matrices)
- Random
- Serialization
- Sort
- Thread
- Tokenizer
- uBlas (Basic Linear Algebra)
Installing Boost
Installing under a Linux OS
The Boost API is easily installed under most Linux distributions by installing the relevant packages. For example, run the following commands to install it for Ubuntu/Debian Linux:
sudo apt-get install libboost-all-dev
Installing under Mac OSX
If you're using homebrew, install boost using this command:
brew install boost
If you're using macports, install boost using this command:
sudo port install boost
Installing under Microsoft Windows
Installing Boost in windows is slightly more complicated as it requires building the library from its source code.
Follow these steps to build the Boost libraries with the MinGW64 GCC compiler:
- Download the source code archive from - http://www.boost.org/users/download/#live . Its preferred to download the 7z archive since its smaller.
- Unpack it into a folder in your machine, for example - c:\boost.
- Change to the main folder and run the bootstrap command specifying the compiler to be used - which is gcc in this case: c:\boost\bootstrap.bat gcc
- Build it with this b2 command (I've included both static and shared libraries, and multi threading support):
\b2 --prefix=c:\mingw_64\boost64 toolset=gcc address-model=64 variant=debug,release link=static,shared threading=multi install
This will compile the libraries and store them into the folder c:\mingw_64\boost64 which will contain all the boost headers and libraries.
Next, set these paths in your environment:
- BOOST_INCLUDEDIR=C:\mingw-w64\boost64\include\boost-1_64;
- CPATH=C:\mingw-w64\boost64\include\boost-1_64;
- LIBRARY_PATH=C:\mingw-w64\boost64\lib;
- LIB=C:\mingw-w64\boost64\lib;
- PATH=%PATH%;C:\mingw-w64\boost64\lib;
An example with boost lambda
The following example program shows how the boost lambda library can be used. Since boost.lambda is a header-only library, you simply need to ensure the library headers are present in the INCLUDE search path or explicitly set in the C++ project's compiler settings.
#include <boost/regex.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/lambda.hpp>
#include <string>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
int main(){
using namespace boost::lambda;
typedef std::istream_iterator<int> in;
for_each(
in(std::cin), in(), cout << (_1 * 3) << " " );
in(std::cin), in(), cout << (_1 * 3) << " " );
return(0);
}
}
In case you've statically linked to a boost library, ensure that your application is re-compiled with updated versions as and when the libraries are updated to resolve bugs and speed up their performance.
Writing good unit-tests and fitness tests helps make the re-compilation process easier.
Continue Learning Boost
The following resources will help you further understand Boost for applying it in your project:
- The boost documentation - http://www.boost.org/doc/libs/
- Using the C++ Standard and Boost Libraries - https://www.youtube.com/watch?v=zxzyntAwtgc
- Introducing the Boost C++ Libraries - https://www.packtpub.com/books/content/introducing-boost-c-libraries
- Beyond the C++ Standard Library: An Introduction to Boost - https://www.amazon.com/dp/0321133544/
- A Short Introduction to Selected Classes of the Boost C++ Library - http://quantlib.org/slides/dima-boost-intro.pdf
- An Introduction to Boost- CodeProject - https://www.codeproject.com/Articles/4496/An-Introduction-to-Boost
- The Boost C++ Libraries, Boris Schäling - https://theboostcpplibraries.com/
- Alex Ott's blog - http://alexott.blogspot.in/search/label/boost
- A well-connected C++14 Boost.Graph tutorial - https://github.com/richelbilderbeek/BoostGraphTutorial/blob/master/boost_graph_tutorial.pdf
- The Boost License - http://www.boost.org/users/license.html
- How did Boost start - http://www.boost.org/users/proposal.pdf
Comments
Post a Comment