Boost library

From Free net encyclopedia

(Difference between revisions)

Current revision

Image:Boost.png Boost is a collection of libraries that extend the functionality of [[C++]]. The libraries are licensed under the Boost Software License, a very open license designed to allow Boost to be used with any project. Several Boost libraries have been accepted for incorporation into the next library technical report of the C++ standard committee (many of Boost's founders are on the committee).

Boost has a noticeable bias towards researching and extending the metaprogramming and generic programming features of the C++ language, with extensive use of templates. Because of very thorough peer review and quality control, libraries included in Boost exhibit very high quality. In order to use these libraries the programmer needs to be familiar with "modern C++".

Contents

Libraries

Boost provides extension libraries in the following areas:

  • Algorithms
  • Workarounds for Broken Compilers
  • Concurrent Programming (Threads)
  • Containers
  • Correctness and testing
  • Data Structures
  • Function Objects and Higher-Order Programming
  • Generic Programming
  • Graphs
  • Input/Output
  • Interlanguage Support
  • Iterators
  • Math and Numerics
  • Memory
  • Misc
  • Parser
  • Preprocessor Metaprogramming
  • Smart pointers (shared_ptr), with automatic reference counting[1]
  • String and Text Processing
  • Template Metaprogramming

Linear algebra

Boost includes a linear algebra library called uBLAS, with BLAS support for vectors and matrices.

  • Example showing how to multiply a vector with a matrix:
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>

using namespace boost::numeric::ublas;

/* "y = Ax" example */
int main () {
	vector<double> x (2);
	x(0) = 1; x(1) = 2;

	matrix<double> A(2,2);
	A(0,0) = 0; A(0,1) = 1;
	A(1,0) = 2; A(1,1) = 3;

	vector<double> y = prod(A, x);

	std::cout << y << std::endl;
	return 0;
}

Check the uBLAS documentation and overview of matrix and vector operations for more details.

Generating random numbers

Boost provides several pseudo-random number generators, together with several target distributions.

#include <boost/random.hpp>
#include <ctime>

using namespace boost;

double SampleNormal (double mean, double sigma)
{
    // select random number generator
    mt19937 rng;
    // seed generator with #seconds since 1970
    rng.seed(static_cast<unsigned> (std::time(0)));

    // select desired probability distribution
    normal_distribution<double> norm_dist(mean, sigma);

    // bind random number generator to distribution, forming a function
    variate_generator<mt19937&, normal_distribution<double> >  normal_sampler(rng, norm_dist);

    // sample from the distribution
    return normal_sampler();
}

Check Boost Random Number Library for more details.

People associated with Boost

Author of several books on C++, Nicolai Josuttis contributed the Boost array library in 2001. Original founders of Boost still active in the community include Beman Dawes and David Abrahams.

External links

Template:Wikibookschapter


[[Category:C++ libraries]]

de:Boost ru:Boost (библиотека)