Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Chapter 7. Boost.Container

Ion Gaztanaga

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Table of Contents

Introduction
Building Boost.Container
Tested compilers
Unique features
Containers of Incomplete Types
SCARY iterators
C++ exception handling
Other features
Non-standard containers
stable_vector
flat_(multi)map/set associative containers
devector
slist
static_vector
small_vector
segtor
Extended functionality: Basic extensions
Default initialization for vector-like containers
Ordered range insertion for associative containers (ordered_unique_range, ordered_range)
Constant-time range splice for (s)list
Extended functionality: Configurable containers
Configurable tree-based associative ordered containers
Configurable vector
Configurable static vector
Configurable small vector
Configurable deque / segtor
Configurable devector
Configurable basic_string
Extended functionality: Extended allocators
C++ Conformance
Move and Emplace
Stateful allocators and uses-allocator protocol
Scoped allocators
Insertion hints in associative containers and preserving insertion ordering for elements with equivalent keys
Initializer lists
Null Forward Iterators
Polymorphic Memory Resources
forward_list<T>
vector vs. std::vector exception guarantees
Parameter taken by const reference that can be changed
vector<bool> specialization
Non-standard value initialization using std::memset
Boost container attributes and comparison with standard library implementations
sizeof comparison across major implementations
String Small String Optimization (SSO) comparison across major implementation
deque implementation block/segment size comparison
sizeof value of Boost.Container containers
Indexes and Reference
Indexes
Boost.Container Header Reference
History, acknowledgements and Release Notes
Boost.Container history
Acknowledgements, notes and links
Release Notes

Boost.Container library implements several well-known containers, including STL containers. The aim of the library is to offer advanced features not present in standard containers or to offer the latest standard draft features for compilers that don't comply with the latest C++ standard.

In short, what does Boost.Container offer?

  • Access to many of the latest C++ standard features and have an easy code migration when you change your compiler.
  • A portable, high performance implementation that works when compiling without exceptions support and offers customized error handling when a container needs to signal an exceptional error.
  • Users obtain a more uniform performance across all plataforms, including SCARY iterators.
  • Userful polymorphic allocators and memory resources, including implementation and emulation for pre-C++17 compilers
  • New advanced features (e.g. recursive containers) and configurability options for containers.
  • Containers support stateful allocators and are compatible with Boost.Interprocess (they can be safely placed in shared memory) offering improved performance vs standard containers when using Boost.Interprocess.
  • You have very useful non-standard containers like [stable/static/small]_vector, flat_[multi]set/map, devector or segtor.
  • If you work on multiple platforms, you'll have a portable behaviour without depending on the std-lib implementation conformance for each platform. Some examples:
  • Extended functionality beyond the standard based on user feedback to improve code performance.
  • Configuration options that allow tweaking containers to fit users needs.
  • The library offers new useful containers:
    • flat_map, flat_set, flat_multimap and flat_multiset: drop-in replacements for standard associative containers but more memory friendly and with faster searches.
    • stable_vector: a std::list and std::vector hybrid container: vector-like random-access iterators and list-like iterator stability in insertions and erasures.
    • static_vector: a vector-like container that internally embeds (statically allocates) all needed memory up to the maximum capacity. Maximum capacity can't be increased and it's specified at compile time.
    • small_vector: a vector-like container that internally embeds (statically allocates) a minimum amount of memory, but dynamically allocates elements when capacity has to be increased. This minimum capacity is specified at compile time.
    • devector: is a hybrid of the standard vector and deque containers. It offers cheap (amortized constant time) insertion at both the front and back ends.
    • segtor: a sequence container with segmented (block-based) storage like deque but only growth at the back; constant-time push_back/pop_back, random access.
    • slist: the classic pre-standard singly linked list implementation offering constant-time size(). Note that C++11 forward_list has no size().

There is no need to compile Boost.Container, since it's a header-only library, just include your Boost header directory in your compiler include path except if you use:

Those exceptions are are implemented as a separately compiled library, so in those cases you must install binaries in a location that can be found by your linker. If you followed the Boost Getting Started instructions, that's already been done for you.

Boost.Container requires a decent C++03 compatibility. Some compilers known to work are:

  • Visual C++ >= 10.0
  • GCC >= 4.8

PrevUpHomeNext