Georgia Water/Best Practices/Conservation - Wikibooks, open books for an open world

C++ Programming/Libraries/Boost – Wikibooks, open books for an open world

Increase Library[edit]

The Increase library ( offers free peer-reviewed, open supply libraries that stretch the performance of C++. Many of the libraries are licensed below the Increase Software program License, designed to permit Increase for use with each open and closed supply tasks.

A lot of Increase’s founders are on the C++ customary committee and a number of other Increase libraries have been accepted for incorporation into the Technical Report 1 of C++0x. Though Increase was begun by members of the C++ Requirements Committee Library Working Group, participation has expanded to incorporate hundreds of programmers from the C++ neighborhood at giant.

The emphasis is on libraries which work effectively with the C++ Commonplace Library. The libraries are geared toward a variety of C++ customers and utility domains, and are in common use by hundreds of programmers. They vary from general-purpose libraries like SmartPtr, to OS Abstractions like FileSystem, to libraries primarily geared toward different library builders and superior C++ customers, like MPL.

An extra objective is to determine “present follow” and supply reference implementations in order that Increase libraries are appropriate for eventual standardization. Ten Increase libraries will likely be included within the C++ Requirements Committee’s upcoming C++ Commonplace Library Technical Report as a step towards turning into a part of a future C++ Commonplace.

As a way to guarantee effectivity and suppleness, Increase makes intensive use of templates. Increase has been a supply of in depth work and analysis into generic programming and metaprogramming in C++.

extension libraries[edit]

  • Algorithms
  • Concurrent programming (threads)
  • Containers
    • array – Administration of fixed-size arrays with STL container semantics
    • Increase Graph Library (BGL) – Generic graph containers, parts and algorithms
    • multi-array – Simplifies creation of N-dimensional arrays
    • multi-index containers – Containers with in-built indexes that enable totally different sorting and entry semantics
    • pointer containers – Containers modeled after most traditional STL containers that enable for clear administration of tips that could values
    • property map – Interface specs within the type of ideas and a basic goal interface for mapping key values to things
    • variant – A secure and generic stack-based object container that permits for the environment friendly storage of and entry to an object of a sort that may be chosen from amongst a set of varieties that have to be specified at compile time.
  • Correctness and testing
    • idea verify – Permits for the enforcement of precise template parameter necessities (ideas)
    • static assert – Compile time assertion assist
    • Increase Take a look at Library – A matched set of parts for writing take a look at applications, organizing assessments into take a look at instances and take a look at suites, and controlling their runtime execution
  • Knowledge buildings
  • Perform objects and higher-order programming
    • bind and mem_fn – Normal binders for capabilities, perform objects, perform pointers and member capabilities
    • perform – Perform object wrappers for deferred calls. Additionally, offers a generalized mechanism for callbacks
    • useful – Enhancements to the perform object adapters specified within the C++ Commonplace Library, together with:
    • hash – An implementation of the hash perform object specified by the C++ Technical Report 1 (TR1). Can be utilized because the default hash perform for unordered associative containers
    • lambda – Within the spirit of lambda abstractions, permits for the definition of small nameless perform objects and operations on these objects at a name web site, utilizing placeholders, particularly to be used with deferred callbacks from algorithms.
    • ref – Supplies utility class templates for enhancing the capabilities of ordinary C++ references, particularly to be used with generic capabilities
    • result_of – Helps within the dedication of the kind of a name expression
    • indicators and slots – Managed indicators and slots callback implementation
  • Generic programming
  • Graphs
  • Enter/output
  • Interlanguage assist (for Python)
  • Iterators
    • iterators
    • operators – Class templates that assist with overloaded operator definitions for consumer outlined iterators and courses that may take part in arithmetic computation.
    • tokenizer – Supplies a view of a set of tokens contained in a sequence that makes them seem as a container with iterator entry
  • Math and Numerics
  • Reminiscence
    • pool – Supplies a easy segregated storage primarily based reminiscence administration scheme
    • smart_ptr – A group of sensible pointer class templates with totally different pointee administration semantics
      • scoped_ptr – Owns the pointee (single object)
      • scoped_array – Like scoped_ptr, however for arrays
      • shared_ptr – Probably shares the pointer with different shared_ptrs. Pointee is destroyed when final shared_ptr to it’s destroyed
      • shared_array – Like shared_ptr, however for arrays
      • weak_ptr – Supplies a “weak” reference to an object that’s already managed by a shared_ptr
      • intrusive_ptr – Similared to shared_ptr, however makes use of a reference rely offered by the pointee
    • utility – Miscellaneous assist courses, together with:
      • base from member idiom – Supplies a workaround for a category that should initialize a member of a base class inside its personal (i.e., the derived class’) constructor’s initializer listing
      • checked delete – Test if an try is made to destroy an object or array of objects utilizing a pointer to an incomplete kind
      • subsequent and prior capabilities – Permit for simpler movement of a ahead or bidirectional iterator, particularly when the outcomes of such a movement should be saved in a separate iterator (i.e., shouldn’t change the unique iterator)
      • noncopyable – Permits for the prohibition of copy development and duplicate task
      • addressof – Permits for the acquisition of an object’s actual handle, bypassing any overloads of operator&(), within the course of
      • result_of – Helps within the dedication of the kind of a name expression
  • Miscellaneous
  • Parsers
  • Preprocessor metaprogramming
  • String and textual content processing
    • lexical_cast – Kind conversions to/from textual content
    • format – Kind secure argument formatting in accordance with a format string
    • iostreams – C++ streams and stream buffer help for brand new sources/sinks, filters framework
    • regex – Help for normal expressions
    • Spirit – An object-oriented recursive-descent parser generator framework
    • string algorithms – A group of assorted algorithms associated to strings
    • tokenizer – Permits for the partitioning of a string or different character sequence into tokens
    • wave – Requirements conformant implementation of the mandated C99 / C++ pre-processor performance packed behind a straightforward to make use of interface
  • Template metaprogramming
    • mpl – A basic goal high-level metaprogramming framework of compile-time algorithms, sequences and metafunctions
    • static assert – Compile time assertion assist
    • kind traits – Templates that outline the elemental properties of varieties
  • Workarounds for damaged compilers

The present Increase launch comprises 87 particular person libraries, together with the next three:


The enhance::noncopyable utility class that ensures that objects of a category are by no means copied.

class C : enhance::noncopyable

Linear algebra – uBLAS[edit]

Increase contains the uBLAS linear algebra library (sooner different libraries embrace armadillo and eigen), with BLAS assist for vectors and matrices. uBlas helps a variety of linear algebra operations, and has bindings to some broadly used numerics libraries, equivalent to ATLAS, BLAS and LAPACK.

  • Instance exhibiting methods to multiply a vector with a matrix:

utilizing namespace enhance::numeric::ublas;

/* "y = Ax" instance */
int primary () 
      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;

Producing random numbers – Increase.Random[edit]

Increase offers distribution-independent pseudorandom quantity mills and PRNG-independent likelihood distributions, that are mixed to construct a concrete generator.


utilizing namespace enhance;

double SampleNormal (double imply, double sigma)
    // Create a Mersenne tornado random quantity generator
    // that's seeded as soon as with #seconds since 1970
    static mt19937 rng(static_cast<unsigned> (std::time(0)));

    // choose Gaussian likelihood distribution
    normal_distribution<double> norm_dist(imply, sigma);

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

    // pattern from the distribution
    return normal_sampler();

See Increase Random Quantity Library for extra particulars.

Multi-threading – Increase.Thread[edit]

Instance code that demonstrates creation of threads:


utilizing namespace std;

void hello_world() 
  cout << "Good day world, I am a thread!" << endl;

int primary(int argc, char* argv[]) 
  // begin two new threads that calls the "hello_world" perform
  enhance::thread my_thread1(&hello_world);
  enhance::thread my_thread2(&hello_world);

  // look forward to each threads to complete a part of(); a part of();
  return 0;

See additionally Threading with Increase – Half I: Creating Threads

Thread locking[edit]

Instance utilization of a mutex to implement unique entry to a perform:


void locked_function ()
    // perform entry mutex
    static enhance::mutex m;
    // look forward to mutex lock
    enhance::mutex::scoped_lock lock(m);

    // crucial part
    // TODO: Do one thing

    // auto-unlock on return

int primary (int argc, char* argv[]) 
    return 0;

Instance of learn/write locking of a property:


/** Normal class for thread-safe properties of any kind. */
template <class T>
class lock_prop : enhance::noncopyable {
    lock_prop () {}

    /** Set property worth. */
    void operator = (const T & v) {
        // look forward to unique write entry
        enhance::unique_lock<enhance::shared_mutex> lock(mutex);

        worth = v;

    /** Get property worth. */
    T operator () () const {
        // look forward to shared learn entry
        enhance::shared_lock<enhance::shared_mutex> lock(mutex);

        return worth;

    /// Property worth.
    T                           worth;
    /// Mutex to limit entry
    mutable enhance::shared_mutex mutex;

int primary () {
    // learn/write locking property
    lock_prop<int> p1;
    p1 = 10;
    int a = p1();

    return 0;

Leave a Reply

Your email address will not be published. Required fields are marked *