Boost C++ Libraries

From Encoresoup - The Ultimate Guide to Free/Open Source Software

Jump to: navigation, search
This article contains content from the Wikipedia article:
Boost C++ Libraries
history contributors

Boost C++ Libraries
Image:Boost.png
Boost logo
Stable release

1.36.0  (14 August 2008)

Genre: Libraries
License: Boost Software License
Website: http://www.boost.org/


The Boost C++ Libraries are a collection of peer-reviewed, open source libraries that extend the functionality of C++. Most of the libraries are licensed under the Boost Software License, designed to allow Boost to be used with both open and closed source projects. Many of Boost's founders are on the C++ standard committee and several Boost libraries have been accepted for incorporation into the Technical Report 1 of C++0x.[1]

The libraries are aimed at a wide range of C++ users and application domains. They range from general-purpose libraries like the smart_ptr library, to OS abstractions like FileSystem, to libraries primarily aimed at other library developers and advanced C++ users, like the MPL.

In order to ensure efficiency and flexibility, Boost makes extensive use of templates. Boost has been a source of extensive work and research into generic programming and metaprogramming in C++.

Contents

[edit] Examples

The current Boost release contains 87 individual libraries, including the following three:

[edit] Linear algebra – uBLAS

Boost includes the uBLAS linear algebra library, 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>
#include <iostream>
 
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;
}

[edit] Generating random numbers – Boost.Random

Boost provides distribution-independent pseudorandom number generators and PRNG-independent probability distributions, which are combined to build a concrete generator.

  • Example showing how to sample from a normal distribution using the Mersenne Twister generator:
#include <boost/random.hpp>
#include <ctime>
 
using namespace boost;
 
double SampleNormal (double mean, double sigma)
{
    // Create a Mersenne twister random number generator
    // that is seeded once with #seconds since 1970
    static mt19937 rng(static_cast<unsigned> (std::time(0)));
 
    // select Gaussian 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();
}

See Boost Random Number Library for more details.

[edit] Multithreading – Boost.Thread

Example code that demonstrates creation of threads:

#include <boost/thread/thread.hpp>
#include <iostream>
 
using namespace std; 
 
void hello_world() 
{
  cout << "Hello world, I'm a thread!" << endl;
}
 
int main(int argc, char* argv[]) 
{
  // start a new thread that calls the "hello_world" function
  boost::thread my_thread(&hello_world);
  // wait for the thread to finish
  my_thread.join();
 
  return 0;
}

[edit] Associated people

Original founders of Boost still active in the community include Beman Dawes and David Abrahams. Author of several books on C++, Nicolai Josuttis contributed the Boost array library in 2001. Around 3,000 people are subscribed to Boost mail-list and dozens of them are very active (as of 2007).

[edit] See also

  • Jam — Boost includes a package called Boost.Build, which uses a special version of Perforce Jam called Boost.Jam

[edit] References

[edit] External links

Wikibooks
Wikibooks has more on the topic of
Personal tools

The Ruby Programming Language [Amazon] Media Tank - HD and DVD Enclosure + card reader [ThinkGeek] LED Binary Watch - Yes, it shows the time in Binary! [ThinkGeek]