Squashed 'third_party/boostorg/container/' content from commit 1ad6431
Change-Id: I7d095db3455264c03446268e5675b926bebedb0a
git-subtree-dir: third_party/boostorg/container
git-subtree-split: 1ad64316a432a7f021b4956acf88abc6aaa8a77e
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..3e84d7c
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,96 @@
+* text=auto !eol svneol=native#text/plain
+*.gitattributes text svneol=native#text/plain
+
+# Scriptish formats
+*.bat text svneol=native#text/plain
+*.bsh text svneol=native#text/x-beanshell
+*.cgi text svneol=native#text/plain
+*.cmd text svneol=native#text/plain
+*.js text svneol=native#text/javascript
+*.php text svneol=native#text/x-php
+*.pl text svneol=native#text/x-perl
+*.pm text svneol=native#text/x-perl
+*.py text svneol=native#text/x-python
+*.sh eol=lf svneol=LF#text/x-sh
+configure eol=lf svneol=LF#text/x-sh
+
+# Image formats
+*.bmp binary svneol=unset#image/bmp
+*.gif binary svneol=unset#image/gif
+*.ico binary svneol=unset#image/ico
+*.jpeg binary svneol=unset#image/jpeg
+*.jpg binary svneol=unset#image/jpeg
+*.png binary svneol=unset#image/png
+*.tif binary svneol=unset#image/tiff
+*.tiff binary svneol=unset#image/tiff
+*.svg text svneol=native#image/svg%2Bxml
+
+# Data formats
+*.pdf binary svneol=unset#application/pdf
+*.avi binary svneol=unset#video/avi
+*.doc binary svneol=unset#application/msword
+*.dsp text svneol=crlf#text/plain
+*.dsw text svneol=crlf#text/plain
+*.eps binary svneol=unset#application/postscript
+*.gz binary svneol=unset#application/gzip
+*.mov binary svneol=unset#video/quicktime
+*.mp3 binary svneol=unset#audio/mpeg
+*.ppt binary svneol=unset#application/vnd.ms-powerpoint
+*.ps binary svneol=unset#application/postscript
+*.psd binary svneol=unset#application/photoshop
+*.rdf binary svneol=unset#text/rdf
+*.rss text svneol=unset#text/xml
+*.rtf binary svneol=unset#text/rtf
+*.sln text svneol=native#text/plain
+*.swf binary svneol=unset#application/x-shockwave-flash
+*.tgz binary svneol=unset#application/gzip
+*.vcproj text svneol=native#text/xml
+*.vcxproj text svneol=native#text/xml
+*.vsprops text svneol=native#text/xml
+*.wav binary svneol=unset#audio/wav
+*.xls binary svneol=unset#application/vnd.ms-excel
+*.zip binary svneol=unset#application/zip
+
+# Text formats
+.htaccess text svneol=native#text/plain
+*.bbk text svneol=native#text/xml
+*.cmake text svneol=native#text/plain
+*.css text svneol=native#text/css
+*.dtd text svneol=native#text/xml
+*.htm text svneol=native#text/html
+*.html text svneol=native#text/html
+*.ini text svneol=native#text/plain
+*.log text svneol=native#text/plain
+*.mak text svneol=native#text/plain
+*.qbk text svneol=native#text/plain
+*.rst text svneol=native#text/plain
+*.sql text svneol=native#text/x-sql
+*.txt text svneol=native#text/plain
+*.xhtml text svneol=native#text/xhtml%2Bxml
+*.xml text svneol=native#text/xml
+*.xsd text svneol=native#text/xml
+*.xsl text svneol=native#text/xml
+*.xslt text svneol=native#text/xml
+*.xul text svneol=native#text/xul
+*.yml text svneol=native#text/plain
+boost-no-inspect text svneol=native#text/plain
+CHANGES text svneol=native#text/plain
+COPYING text svneol=native#text/plain
+INSTALL text svneol=native#text/plain
+Jamfile text svneol=native#text/plain
+Jamroot text svneol=native#text/plain
+Jamfile.v2 text svneol=native#text/plain
+Jamrules text svneol=native#text/plain
+Makefile* text svneol=native#text/plain
+README text svneol=native#text/plain
+TODO text svneol=native#text/plain
+
+# Code formats
+*.c text svneol=native#text/plain
+*.cpp text svneol=native#text/plain
+*.h text svneol=native#text/plain
+*.hpp text svneol=native#text/plain
+*.ipp text svneol=native#text/plain
+*.tpp text svneol=native#text/plain
+*.jam text svneol=native#text/plain
+*.java text svneol=native#text/plain
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..cbed577
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,63 @@
+# Copyright 2016, 2017 Peter Dimov
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
+
+language: cpp
+
+sudo: false
+
+python: "2.7"
+
+branches:
+ only:
+ - master
+ - develop
+ - /feature\/.*/
+
+env:
+ matrix:
+ - BOGUS_JOB=true
+
+matrix:
+
+ exclude:
+ - env: BOGUS_JOB=true
+
+ include:
+ - os: linux
+ compiler: g++
+ env: TOOLSET=gcc CXXSTD=03,11
+
+ - os: linux
+ compiler: clang++
+ env: TOOLSET=clang CXXSTD=03,11,14,1z
+ addons:
+ apt:
+ packages:
+ - libstdc++-4.9-dev
+ sources:
+ - ubuntu-toolchain-r-test
+
+ - os: osx
+ compiler: clang++
+ env: TOOLSET=clang CXXSTD=03,11,14,1z
+
+install:
+ - BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
+ - cd ..
+ - git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost-root
+ - cd boost-root
+ - git submodule update --init tools/build
+ - git submodule update --init libs/config
+ - git submodule update --init tools/boostdep
+ - cp -r $TRAVIS_BUILD_DIR/* libs/container
+ - python tools/boostdep/depinst/depinst.py container
+ - ./bootstrap.sh
+ - ./b2 headers
+
+script:
+ - ./b2 libs/container/test toolset=$TOOLSET cxxstd=$CXXSTD
+
+notifications:
+ email:
+ on_success: always
diff --git a/Jamfile b/Jamfile
new file mode 100644
index 0000000..c55393e
--- /dev/null
+++ b/Jamfile
@@ -0,0 +1,11 @@
+# Boost.Container Library Jamfile
+#
+# Copyright (c) 2018 Ion Gaztanaga
+#
+# Use, modification, and distribution are subject to 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)
+
+# please order by name to ease maintenance
+build-project example ;
+build-project test ;
diff --git a/bench/Jamfile.v2 b/bench/Jamfile.v2
new file mode 100644
index 0000000..9cf993d
--- /dev/null
+++ b/bench/Jamfile.v2
@@ -0,0 +1,34 @@
+# Boost Container Library Test Jamfile
+
+# (C) Copyright Ion Gaztanaga 2009.
+# Use, modification and distribution are subject to 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)
+
+# Adapted from John Maddock's TR1 Jamfile.v2
+# Copyright John Maddock 2005.
+# Use, modification and distribution are subject to 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)
+
+# this rule enumerates through all the sources and invokes
+# the run rule for each source, the result is a list of all
+# the run rules, which we can pass on to the test_suite rule:
+
+rule test_all
+{
+ local all_rules = ;
+
+ for local fileb in [ glob *.cpp ]
+ {
+ all_rules += [ run $(fileb) /boost/container//boost_container /boost/timer//boost_timer
+ : # additional args
+ : # test-files
+ : # requirements
+ ] ;
+ }
+
+ return $(all_rules) ;
+}
+
+test-suite container_bench : [ test_all r ] ;
diff --git a/bench/bench_adaptive_node_pool.cpp b/bench/bench_adaptive_node_pool.cpp
new file mode 100644
index 0000000..8b33012
--- /dev/null
+++ b/bench/bench_adaptive_node_pool.cpp
@@ -0,0 +1,335 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2013. 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)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+//Enable checks in debug mode
+#ifndef NDEBUG
+#define BOOST_CONTAINER_ADAPTIVE_NODE_POOL_CHECK_INVARIANTS
+#endif
+
+#ifdef _MSC_VER
+#pragma warning (disable : 4512)
+#pragma warning (disable : 4127)
+#pragma warning (disable : 4244)
+#pragma warning (disable : 4267)
+#endif
+
+#include <boost/container/adaptive_pool.hpp>
+#include <boost/container/node_allocator.hpp>
+#include <boost/container/allocator.hpp>
+#include <boost/container/list.hpp>
+#include <memory> //std::allocator
+#include <iostream> //std::cout, std::endl
+#include <vector> //std::vector
+#include <cstddef> //std::size_t
+#include <cassert> //assert
+
+#include <boost/timer/timer.hpp>
+using boost::timer::cpu_timer;
+using boost::timer::cpu_times;
+using boost::timer::nanosecond_type;
+
+namespace bc = boost::container;
+
+typedef std::allocator<int> StdAllocator;
+typedef bc::allocator<int, 2> AllocatorPlusV2;
+typedef bc::allocator<int, 1> AllocatorPlusV1;
+typedef bc::adaptive_pool
+ < int
+ , bc::ADP_nodes_per_block
+ , bc::ADP_max_free_blocks
+ , bc::ADP_only_alignment
+ , 1> AdPoolAlignOnlyV1;
+typedef bc::adaptive_pool
+ < int
+ , bc::ADP_nodes_per_block
+ , bc::ADP_max_free_blocks
+ , bc::ADP_only_alignment
+ , 2> AdPoolAlignOnlyV2;
+typedef bc::adaptive_pool
+ < int
+ , bc::ADP_nodes_per_block
+ , bc::ADP_max_free_blocks
+ , 2
+ , 1> AdPool2PercentV1;
+typedef bc::adaptive_pool
+ < int
+ , bc::ADP_nodes_per_block
+ , bc::ADP_max_free_blocks
+ , 2
+ , 2> AdPool2PercentV2;
+typedef bc::node_allocator
+ < int
+ , bc::NodeAlloc_nodes_per_block
+ , 1> SimpleSegregatedStorageV1;
+typedef bc::node_allocator
+ < int
+ , bc::NodeAlloc_nodes_per_block
+ , 2> SimpleSegregatedStorageV2;
+
+//Explicit instantiation
+template class bc::adaptive_pool
+ < int
+ , bc::ADP_nodes_per_block
+ , bc::ADP_max_free_blocks
+ , bc::ADP_only_alignment
+ , 2>;
+
+template class bc::node_allocator
+ < int
+ , bc::NodeAlloc_nodes_per_block
+ , 2>;
+
+template<class Allocator> struct get_allocator_name;
+
+template<> struct get_allocator_name<StdAllocator>
+{ static const char *get() { return "StdAllocator"; } };
+
+template<> struct get_allocator_name<AllocatorPlusV2>
+{ static const char *get() { return "AllocatorPlusV2"; } };
+
+template<> struct get_allocator_name<AllocatorPlusV1>
+{ static const char *get() { return "AllocatorPlusV1"; } };
+
+template<> struct get_allocator_name<AdPoolAlignOnlyV1>
+{ static const char *get() { return "AdPoolAlignOnlyV1"; } };
+
+template<> struct get_allocator_name<AdPoolAlignOnlyV2>
+{ static const char *get() { return "AdPoolAlignOnlyV2"; } };
+
+template<> struct get_allocator_name<AdPool2PercentV1>
+{ static const char *get() { return "AdPool2PercentV1"; } };
+
+template<> struct get_allocator_name<AdPool2PercentV2>
+{ static const char *get() { return "AdPool2PercentV2"; } };
+
+template<> struct get_allocator_name<SimpleSegregatedStorageV1>
+{ static const char *get() { return "SimpleSegregatedStorageV1"; } };
+
+template<> struct get_allocator_name<SimpleSegregatedStorageV2>
+{ static const char *get() { return "SimpleSegregatedStorageV2"; } };
+
+class MyInt
+{
+ std::size_t int_;
+
+ public:
+ explicit MyInt(std::size_t i = 0) : int_(i){}
+ MyInt(const MyInt &other)
+ : int_(other.int_)
+ {}
+ MyInt & operator=(const MyInt &other)
+ {
+ int_ = other.int_;
+ return *this;
+ }
+};
+
+template<class Allocator>
+void list_test_template(std::size_t num_iterations, std::size_t num_elements, bool csv_output)
+{
+ typedef typename Allocator::template rebind<MyInt>::other IntAllocator;
+ nanosecond_type tinsert, terase;
+ bc::dlmalloc_malloc_stats_t insert_stats, erase_stats;
+ std::size_t insert_inuse, erase_inuse;
+ const size_t sizeof_node = 2*sizeof(void*)+sizeof(int);
+
+ typedef bc::list<MyInt, IntAllocator> list_t;
+ typedef typename list_t::iterator iterator_t;
+ {
+ cpu_timer timer;
+ timer.resume();
+ list_t l;
+ for(std::size_t r = 0; r != num_iterations; ++r){
+ l.insert(l.end(), num_elements, MyInt(r));
+ }
+ timer.stop();
+ tinsert = timer.elapsed().wall;
+
+ insert_inuse = bc::dlmalloc_in_use_memory();
+ insert_stats = bc::dlmalloc_malloc_stats();
+/*
+ iterator_t it(l.begin());
+ iterator_t last(--l.end());
+ for(std::size_t n_elem = 0, n_max = l.size()/2-1; n_elem != n_max; ++n_elem)
+ {
+ l.splice(it++, l, last--);
+ }
+*/
+ //l.reverse();
+
+ //Now preprocess erase ranges
+ std::vector<iterator_t> ranges_to_erase;
+ ranges_to_erase.push_back(l.begin());
+ for(std::size_t r = 0; r != num_iterations; ++r){
+ iterator_t next_pos(ranges_to_erase[r]);
+ std::size_t n = num_elements;
+ while(n--){ ++next_pos; }
+ ranges_to_erase.push_back(next_pos);
+ }
+
+ //Measure range erasure function
+ timer.start();
+ for(std::size_t r = 0; r != num_iterations; ++r){
+ assert((r+1) < ranges_to_erase.size());
+ l.erase(ranges_to_erase[r], ranges_to_erase[r+1]);
+ }
+ timer.stop();
+ terase = timer.elapsed().wall;
+ erase_inuse = bc::dlmalloc_in_use_memory();
+ erase_stats = bc::dlmalloc_malloc_stats();
+ }
+
+
+ if(csv_output){
+ std::cout << get_allocator_name<Allocator>::get()
+ << ";"
+ << num_iterations
+ << ";"
+ << num_elements
+ << ";"
+ << float(tinsert)/(num_iterations*num_elements)
+ << ";"
+ << (unsigned int)insert_stats.system_bytes
+ << ";"
+ << float(insert_stats.system_bytes)/(num_iterations*num_elements*sizeof_node)*100.0-100.0
+ << ";"
+ << (unsigned int)insert_inuse
+ << ";"
+ << (float(insert_inuse)/(num_iterations*num_elements*sizeof_node)*100.0)-100.0
+ << ";";
+ std::cout << float(terase)/(num_iterations*num_elements)
+ << ";"
+ << (unsigned int)erase_stats.system_bytes
+ << ";"
+ << (unsigned int)erase_inuse
+ << std::endl;
+ }
+ else{
+ std::cout << std::endl
+ << "Allocator: " << get_allocator_name<Allocator>::get()
+ << std::endl
+ << " allocation/deallocation(ns): " << float(tinsert)/(num_iterations*num_elements) << '\t' << float(terase)/(num_iterations*num_elements)
+ << std::endl
+ << " Sys MB(overh.)/Inuse MB(overh.): " << (float)insert_stats.system_bytes/(1024*1024) << "(" << float(insert_stats.system_bytes)/(num_iterations*num_elements*sizeof_node)*100.0-100.0 << "%)"
+ << " / "
+ << (float)insert_inuse/(1024*1024) << "(" << (float(insert_inuse)/(num_iterations*num_elements*sizeof_node)*100.0)-100.0 << "%)"
+ << std::endl
+ << " system MB/inuse bytes after: " << (float)erase_stats.system_bytes/(1024*1024) << '\t' << bc::dlmalloc_in_use_memory()
+ << std::endl << std::endl;
+ }
+
+ //Release node_allocator cache
+ typedef boost::container::dtl::shared_node_pool
+ < (2*sizeof(void*)+sizeof(int))
+ , AdPoolAlignOnlyV2::nodes_per_block> shared_node_pool_t;
+ boost::container::dtl::singleton_default
+ <shared_node_pool_t>::instance().purge_blocks();
+
+ //Release adaptive_pool cache
+ typedef boost::container::dtl::shared_adaptive_node_pool
+ < (2*sizeof(void*)+sizeof(int))
+ , AdPool2PercentV2::nodes_per_block
+ , AdPool2PercentV2::max_free_blocks
+ , AdPool2PercentV2::overhead_percent> shared_adaptive_pool_plus_t;
+ boost::container::dtl::singleton_default
+ <shared_adaptive_pool_plus_t>::instance().deallocate_free_blocks();
+
+ //Release adaptive_pool cache
+ typedef boost::container::dtl::shared_adaptive_node_pool
+ < (2*sizeof(void*)+sizeof(int))
+ , AdPool2PercentV2::nodes_per_block
+ , AdPool2PercentV2::max_free_blocks
+ , 0u> shared_adaptive_pool_plus_align_only_t;
+ boost::container::dtl::singleton_default
+ <shared_adaptive_pool_plus_align_only_t>::instance().deallocate_free_blocks();
+ //Release dlmalloc memory
+ bc::dlmalloc_trim(0);
+}
+
+void print_header()
+{
+ std::cout << "Allocator" << ";" << "Iterations" << ";" << "Size" << ";"
+ << "Insertion time(ns)" << ";"
+ << "System bytes" << ";"
+ << "System overhead(%)" << ";"
+ << "In use bytes" << ";"
+ << "In use overhead(%)" << ";"
+ << "Erasure time (ns)" << ";"
+ << "System bytes after" << ";"
+ << "In use bytes after"
+ << std::endl;
+}
+
+int main(int argc, const char *argv[])
+{
+ #define SINGLE_TEST
+ #ifndef SINGLE_TEST
+ #ifdef NDEBUG
+ std::size_t numrep [] = { 300, 3000, 30000, 300000, 600000, 1500000, 3000000 };
+ #else
+ std::size_t numrep [] = { 20, 200, 2000, 20000, 40000, 100000, 200000 };
+ #endif
+ std::size_t numele [] = { 10000, 1000, 100, 10, 5, 2, 1 };
+ #else
+ #ifdef BOOST_CONTAINER_ADAPTIVE_NODE_POOL_CHECK_INVARIANTS
+ std::size_t numrep[] = { 1000 };
+ #elif defined(NDEBUG)
+ std::size_t numrep [] = { 15000 };
+ #else
+ std::size_t numrep [] = { 1000 };
+ #endif
+ std::size_t numele [] = { 100 };
+ #endif
+
+ bool csv_output = argc == 2 && (strcmp(argv[1], "--csv-output") == 0);
+
+ if(csv_output){/*
+ print_header();
+ for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ list_test_template<AllocatorPlusV1>(numrep[i], numele[i], csv_output);
+ }
+ for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ list_test_template<AllocatorPlusV2>(numrep[i], numele[i], csv_output);
+ }
+ for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ list_test_template<AdPoolAlignOnlyV1>(numrep[i], numele[i], csv_output);
+ }
+ for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ list_test_template<AdPoolAlignOnlyV2>(numrep[i], numele[i], csv_output);
+ }
+ for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ list_test_template<AdPool2PercentV1>(numrep[i], numele[i], csv_output);
+ }
+ for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ list_test_template<AdPool2PercentV2>(numrep[i], numele[i], csv_output);
+ }
+ for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ list_test_template<SimpleSegregatedStorageV1>(numrep[i], numele[i], csv_output);
+ }
+ for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ list_test_template<SimpleSegregatedStorageV2>(numrep[i], numele[i], csv_output);
+ }*/
+ }
+ else{
+ for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ std::cout << "\n ----------------------------------- \n"
+ << " Iterations/Elements: " << numrep[i] << "/" << numele[i]
+ << "\n ----------------------------------- \n";
+ list_test_template<AllocatorPlusV1>(numrep[i], numele[i], csv_output);
+ list_test_template<AllocatorPlusV2>(numrep[i], numele[i], csv_output);
+ list_test_template<AdPoolAlignOnlyV1>(numrep[i], numele[i], csv_output);
+ list_test_template<AdPoolAlignOnlyV2>(numrep[i], numele[i], csv_output);
+ list_test_template<AdPool2PercentV1>(numrep[i], numele[i], csv_output);
+ list_test_template<AdPool2PercentV2>(numrep[i], numele[i], csv_output);
+ list_test_template<SimpleSegregatedStorageV1>(numrep[i], numele[i], csv_output);
+ list_test_template<SimpleSegregatedStorageV2>(numrep[i], numele[i], csv_output);
+ }
+ }
+ return 0;
+}
diff --git a/bench/bench_alloc.cpp b/bench/bench_alloc.cpp
new file mode 100644
index 0000000..b05748e
--- /dev/null
+++ b/bench/bench_alloc.cpp
@@ -0,0 +1,184 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2013. 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)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifdef _MSC_VER
+#pragma warning (disable : 4512)
+#endif
+
+#include <boost/container/detail/dlmalloc.hpp>
+
+#define BOOST_INTERPROCESS_VECTOR_ALLOC_STATS
+
+#include <iostream> //std::cout, std::endl
+#include <typeinfo> //typeid
+#include <cassert> //assert
+
+#include <boost/timer/timer.hpp>
+using boost::timer::cpu_timer;
+using boost::timer::cpu_times;
+using boost::timer::nanosecond_type;
+
+using namespace boost::container;
+
+template <class POD>
+void allocation_timing_test(unsigned int num_iterations, unsigned int num_elements)
+{
+ size_t capacity = 0;
+ unsigned int numalloc = 0, numexpand = 0;
+
+ std::cout
+ << " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n"
+ << " Iterations/Elements: " << num_iterations << "/" << num_elements << '\n'
+ << " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n"
+ << std::endl;
+
+
+ allocation_type malloc_types[] = { BOOST_CONTAINER_EXPAND_BWD, BOOST_CONTAINER_EXPAND_FWD, BOOST_CONTAINER_ALLOCATE_NEW };
+ const char * malloc_names[] = { "Backwards expansion", "Forward expansion", "New allocation" };
+ for(size_t i = 0; i < sizeof(malloc_types)/sizeof(allocation_type); ++i){
+ numalloc = 0; numexpand = 0;
+ const allocation_type m_mode = malloc_types[i];
+ const char *malloc_name = malloc_names[i];
+
+ cpu_timer timer;
+ timer.resume();
+
+ for(unsigned int r = 0; r != num_iterations; ++r){
+ void *first_mem = 0;
+ if(m_mode != BOOST_CONTAINER_EXPAND_FWD)
+ first_mem = dlmalloc_malloc(sizeof(POD)*num_elements*3/2);
+ void *addr = dlmalloc_malloc(1*sizeof(POD));
+ if(m_mode == BOOST_CONTAINER_EXPAND_FWD)
+ first_mem = dlmalloc_malloc(sizeof(POD)*num_elements*3/2);
+ capacity = dlmalloc_size(addr)/sizeof(POD);
+ dlmalloc_free(first_mem);
+ ++numalloc;
+
+ try{
+ dlmalloc_command_ret_t ret;
+ for(size_t e = capacity + 1; e < num_elements; ++e){
+ size_t received_size;
+ size_t min = (capacity+1)*sizeof(POD);
+ size_t max = (capacity*3/2)*sizeof(POD);
+ if(min > max)
+ max = min;
+ ret = dlmalloc_allocation_command
+ ( m_mode, sizeof(POD)
+ , min, max, &received_size, addr);
+ if(!ret.first){
+ std::cout << "(!ret.first)!" << std::endl;
+ throw int(0);
+ }
+ if(!ret.second){
+ assert(m_mode == BOOST_CONTAINER_ALLOCATE_NEW);
+ if(m_mode != BOOST_CONTAINER_ALLOCATE_NEW){
+ std::cout << "m_mode != BOOST_CONTAINER_ALLOCATE_NEW!" << std::endl;
+ return;
+ }
+ dlmalloc_free(addr);
+ addr = ret.first;
+ ++numalloc;
+ }
+ else{
+ assert(m_mode != BOOST_CONTAINER_ALLOCATE_NEW);
+ if(m_mode == BOOST_CONTAINER_ALLOCATE_NEW){
+ std::cout << "m_mode == BOOST_CONTAINER_ALLOCATE_NEW!" << std::endl;
+ return;
+ }
+ ++numexpand;
+ }
+ capacity = received_size/sizeof(POD);
+ addr = ret.first;
+ e = capacity + 1;
+ }
+ dlmalloc_free(addr);
+ }
+ catch(...){
+ dlmalloc_free(addr);
+ throw;
+ }
+ }
+
+ assert( dlmalloc_allocated_memory() == 0);
+ if(dlmalloc_allocated_memory()!= 0){
+ std::cout << "Memory leak!" << std::endl;
+ return;
+ }
+
+ timer.stop();
+ nanosecond_type nseconds = timer.elapsed().wall;
+
+ std::cout << " Malloc type: " << malloc_name
+ << std::endl
+ << " allocation ns: "
+ << float(nseconds)/(num_iterations*num_elements)
+ << std::endl
+ << " capacity - alloc calls (new/expand): "
+ << (unsigned int)capacity << " - "
+ << (float(numalloc) + float(numexpand))/num_iterations
+ << "(" << float(numalloc)/num_iterations << "/" << float(numexpand)/num_iterations << ")"
+ << std::endl << std::endl;
+ dlmalloc_trim(0);
+ }
+}
+
+template<unsigned N>
+struct char_holder
+{
+ char ints_[N];
+};
+
+template<class POD>
+int allocation_loop()
+{
+ std::cout << std::endl
+ << "-------------------------------------------\n"
+ << "-------------------------------------------\n"
+ << " Type(sizeof): " << typeid(POD).name() << " (" << sizeof(POD) << ")\n"
+ << "-------------------------------------------\n"
+ << "-------------------------------------------\n"
+ << std::endl;
+
+ #define SINGLE_TEST
+ #ifndef SINGLE_TEST
+ #ifdef NDEBUG
+ unsigned int numrep [] = { /*10000, */10000, 100000, 1000000 };
+ #else
+ unsigned int numrep [] = { /*10000, */1000, 10000, 100000 };
+ #endif
+ unsigned int numele [] = { /*10000, */1000, 100, 10 };
+ #else
+ #ifdef NDEBUG
+ unsigned int numrep [] = { 50000 };
+ #else
+ unsigned int numrep [] = { 5000 };
+ #endif
+ unsigned int numele [] = { 100 };
+ #endif
+
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ allocation_timing_test<POD>(numrep[i], numele[i]);
+ }
+
+ return 0;
+}
+
+int main()
+{
+ dlmalloc_mallopt( (-3)//M_MMAP_THRESHOLD
+ , 100*10000000);
+ //allocation_loop<char_holder<4> >();
+ //allocation_loop<char_holder<6> >();
+ allocation_loop<char_holder<8> >();
+ allocation_loop<char_holder<12> >();
+ //allocation_loop<char_holder<14> >();
+ allocation_loop<char_holder<24> >();
+ return 0;
+}
diff --git a/bench/bench_alloc_expand_bwd.cpp b/bench/bench_alloc_expand_bwd.cpp
new file mode 100644
index 0000000..61bd4da
--- /dev/null
+++ b/bench/bench_alloc_expand_bwd.cpp
@@ -0,0 +1,220 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2013. 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)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifdef _MSC_VER
+#pragma warning (disable : 4512)
+#endif
+
+#include <boost/container/allocator.hpp>
+
+#define BOOST_CONTAINER_VECTOR_ALLOC_STATS
+
+#include <boost/container/vector.hpp>
+#include <memory> //std::allocator
+#include <iostream> //std::cout, std::endl
+#include <cassert> //assert
+
+#include <boost/timer/timer.hpp>
+using boost::timer::cpu_timer;
+using boost::timer::cpu_times;
+using boost::timer::nanosecond_type;
+
+namespace bc = boost::container;
+
+typedef std::allocator<int> StdAllocator;
+typedef bc::allocator<int, 2, bc::expand_bwd | bc::expand_fwd> AllocatorPlusV2Mask;
+typedef bc::allocator<int, 2, bc::expand_fwd> AllocatorPlusV2;
+typedef bc::allocator<int, 1> AllocatorPlusV1;
+
+template<class Allocator> struct get_allocator_name;
+
+template<> struct get_allocator_name<StdAllocator>
+{ static const char *get() { return "StdAllocator"; } };
+
+template<> struct get_allocator_name<AllocatorPlusV2Mask>
+{ static const char *get() { return "AllocatorPlusV2Mask"; } };
+
+template<> struct get_allocator_name<AllocatorPlusV2>
+{ static const char *get() { return "AllocatorPlusV2"; } };
+
+template<> struct get_allocator_name<AllocatorPlusV1>
+{ static const char *get() { return "AllocatorPlusV1"; } };
+
+//typedef int MyInt;
+
+class MyInt
+{
+ int int_;
+
+ public:
+ MyInt(int i = 0)
+ : int_(i)
+ {}
+
+ MyInt(const MyInt &other)
+ : int_(other.int_)
+ {}
+
+ MyInt & operator=(const MyInt &other)
+ {
+ int_ = other.int_;
+ return *this;
+ }
+
+ ~MyInt()
+ {
+ int_ = 0;
+ }
+};
+namespace boost{
+
+template<class T>
+struct has_trivial_destructor_after_move;
+
+template<>
+struct has_trivial_destructor_after_move<MyInt>
+{
+ static const bool value = true;
+ //static const bool value = false;
+};
+
+} //namespace boost{
+
+
+void print_header()
+{
+ std::cout << "Allocator" << ";" << "Iterations" << ";" << "Size" << ";"
+ << "Capacity" << ";" << "push_back(ns)" << ";" << "Allocator calls" << ";"
+ << "New allocations" << ";" << "Bwd expansions" << std::endl;
+}
+
+template<class Allocator>
+void vector_test_template(unsigned int num_iterations, unsigned int num_elements, bool csv_output)
+{
+ typedef typename Allocator::template rebind<MyInt>::other IntAllocator;
+ unsigned int numalloc = 0, numexpand = 0;
+
+ cpu_timer timer;
+ timer.resume();
+
+ unsigned int capacity = 0;
+ for(unsigned int r = 0; r != num_iterations; ++r){
+ bc::vector<MyInt, IntAllocator> v;
+ v.reset_alloc_stats();
+ void *first_mem = 0;
+ try{
+ first_mem = bc::dlmalloc_malloc(sizeof(MyInt)*num_elements*3/2);
+ v.push_back(MyInt(0));
+ bc::dlmalloc_free(first_mem);
+
+ for(unsigned int e = 0; e != num_elements; ++e){
+ v.push_back(MyInt(e));
+ }
+ numalloc += v.num_alloc;
+ numexpand += v.num_expand_bwd;
+ capacity = static_cast<unsigned int>(v.capacity());
+ }
+ catch(...){
+ bc::dlmalloc_free(first_mem);
+ throw;
+ }
+ }
+
+ assert(bc::dlmalloc_allocated_memory() == 0);
+
+ timer.stop();
+ nanosecond_type nseconds = timer.elapsed().wall;
+
+ if(csv_output){
+ std::cout << get_allocator_name<Allocator>::get()
+ << ";"
+ << num_iterations
+ << ";"
+ << num_elements
+ << ";"
+ << capacity
+ << ";"
+ << float(nseconds)/(num_iterations*num_elements)
+ << ";"
+ << (float(numalloc) + float(numexpand))/num_iterations
+ << ";"
+ << float(numalloc)/num_iterations
+ << ";"
+ << float(numexpand)/num_iterations
+ << std::endl;
+ }
+ else{
+ std::cout << std::endl
+ << "Allocator: " << get_allocator_name<Allocator>::get()
+ << std::endl
+ << " push_back ns: "
+ << float(nseconds)/(num_iterations*num_elements)
+ << std::endl
+ << " capacity - alloc calls (new/expand): "
+ << (unsigned int)capacity << " - "
+ << (float(numalloc) + float(numexpand))/num_iterations
+ << "(" << float(numalloc)/num_iterations << "/" << float(numexpand)/num_iterations << ")"
+ << std::endl;
+ std::cout << '\n'
+ << " ----------------------------------- "
+ << std::endl;
+ }
+ bc::dlmalloc_trim(0);
+}
+
+int main(int argc, const char *argv[])
+{
+ #define SINGLE_TEST
+ #ifndef SINGLE_TEST
+ #ifdef NDEBUG
+ unsigned int numit [] = { 2000, 20000, 200000, 2000000 };
+ #else
+ unsigned int numit [] = { 100, 1000, 10000, 100000 };
+ #endif
+ unsigned int numele [] = { 10000, 1000, 100, 10 };
+ #else
+ #ifdef NDEBUG
+ unsigned int numit [] = { 2000 };
+ #else
+ unsigned int numit [] = { 100 };
+ #endif
+ unsigned int numele [] = { 10000 };
+ #endif
+
+ bool csv_output = argc == 2 && (strcmp(argv[1], "--csv-output") == 0);
+
+ if(csv_output){
+ print_header();
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ vector_test_template<StdAllocator>(numit[i], numele[i], csv_output);
+ }
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ vector_test_template<AllocatorPlusV1>(numit[i], numele[i], csv_output);
+ }
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ vector_test_template<AllocatorPlusV2Mask>(numit[i], numele[i], csv_output);
+ }
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ vector_test_template<AllocatorPlusV2>(numit[i], numele[i], csv_output);
+ }
+ }
+ else{
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ std::cout << "\n ----------------------------------- \n"
+ << " Iterations/Elements: " << numit[i] << "/" << numele[i]
+ << "\n ----------------------------------- \n";
+ vector_test_template<StdAllocator>(numit[i], numele[i], csv_output);
+ vector_test_template<AllocatorPlusV1>(numit[i], numele[i], csv_output);
+ vector_test_template<AllocatorPlusV2Mask>(numit[i], numele[i], csv_output);
+ vector_test_template<AllocatorPlusV2>(numit[i], numele[i], csv_output);
+ }
+ }
+ return 0;
+}
diff --git a/bench/bench_alloc_expand_fwd.cpp b/bench/bench_alloc_expand_fwd.cpp
new file mode 100644
index 0000000..2293a0b
--- /dev/null
+++ b/bench/bench_alloc_expand_fwd.cpp
@@ -0,0 +1,198 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2013. 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)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifdef _MSC_VER
+#pragma warning (disable : 4512)
+#pragma warning (disable : 4267)
+#pragma warning (disable : 4244)
+#endif
+
+#define BOOST_CONTAINER_VECTOR_ALLOC_STATS
+
+#include <boost/container/allocator.hpp>
+#include <vector>
+#include <boost/container/vector.hpp>
+
+#include <memory> //std::allocator
+#include <iostream> //std::cout, std::endl
+#include <cstring> //std::strcmp
+#include <boost/timer/timer.hpp>
+#include <typeinfo>
+using boost::timer::cpu_timer;
+using boost::timer::cpu_times;
+using boost::timer::nanosecond_type;
+
+namespace bc = boost::container;
+
+#if defined(BOOST_CONTAINER_VECTOR_ALLOC_STATS)
+
+template<class T, class Allocator>
+static void reset_alloc_stats(std::vector<T, Allocator> &)
+ {}
+
+template<class T, class Allocator>
+static std::size_t get_num_alloc(std::vector<T, Allocator> &)
+ { return 0; }
+
+template<class T, class Allocator>
+static std::size_t get_num_expand(std::vector<T, Allocator> &)
+ { return 0; }
+
+template<class T, class Allocator>
+static void reset_alloc_stats(bc::vector<T, Allocator> &v)
+ { v.reset_alloc_stats(); }
+
+template<class T, class Allocator>
+static std::size_t get_num_alloc(bc::vector<T, Allocator> &v)
+ { return v.num_alloc; }
+
+template<class T, class Allocator>
+static std::size_t get_num_expand(bc::vector<T, Allocator> &v)
+ { return v.num_expand_fwd; }
+
+#endif //BOOST_CONTAINER_VECTOR_ALLOC_STATS
+
+class MyInt
+{
+ int int_;
+
+ public:
+ explicit MyInt(int i = 0)
+ : int_(i)
+ {}
+
+ MyInt(const MyInt &other)
+ : int_(other.int_)
+ {}
+
+ MyInt & operator=(const MyInt &other)
+ {
+ int_ = other.int_;
+ return *this;
+ }
+
+ ~MyInt()
+ {
+ int_ = 0;
+ }
+};
+
+template<class Container>
+void vector_test_template(unsigned int num_iterations, unsigned int num_elements)
+{
+ unsigned int numalloc = 0, numexpand = 0;
+
+ cpu_timer timer;
+ timer.resume();
+
+ unsigned int capacity = 0;
+ for(unsigned int r = 0; r != num_iterations; ++r){
+ Container v;
+ #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
+ reset_alloc_stats(v);
+ #endif
+ //v.reserve(num_elements);
+ //MyInt a[3];
+/*
+ for(unsigned int e = 0; e != num_elements/3; ++e){
+ v.insert(v.end(), &a[0], &a[0]+3);
+ }*/
+/*
+ for(unsigned int e = 0; e != num_elements/3; ++e){
+ v.insert(v.end(), 3, MyInt(e));
+ }*/
+/*
+ for(unsigned int e = 0; e != num_elements/3; ++e){
+ v.insert(v.empty() ? v.end() : --v.end(), &a[0], &a[0]+3);
+ }*/
+/*
+ for(unsigned int e = 0; e != num_elements/3; ++e){
+ v.insert(v.empty() ? v.end() : --v.end(), 3, MyInt(e));
+ }*/
+/*
+ for(unsigned int e = 0; e != num_elements/3; ++e){
+ v.insert(v.size() >= 3 ? v.end()-3 : v.begin(), &a[0], &a[0]+3);
+ }*/
+/*
+ for(unsigned int e = 0; e != num_elements/3; ++e){
+ v.insert(v.size() >= 3 ? v.end()-3 : v.begin(), 3, MyInt(e));
+ }*/
+/*
+ for(unsigned int e = 0; e != num_elements; ++e){
+ v.insert(v.end(), MyInt(e));
+ }*/
+/*
+ for(unsigned int e = 0; e != num_elements; ++e){
+ v.insert(v.empty() ? v.end() : --v.end(), MyInt(e));
+ }*/
+
+ for(unsigned int e = 0; e != num_elements; ++e){
+ v.push_back(MyInt(e));
+ }
+
+ #ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
+ numalloc += get_num_alloc(v);
+ numexpand += get_num_expand(v);
+ #endif
+ capacity = static_cast<unsigned int>(v.capacity());
+ }
+
+ timer.stop();
+ nanosecond_type nseconds = timer.elapsed().wall;
+
+ std::cout << std::endl
+ << "Allocator: " << typeid(typename Container::allocator_type).name()
+ << std::endl
+ << " push_back ns: "
+ << float(nseconds)/(num_iterations*num_elements)
+ << std::endl
+ << " capacity - alloc calls (new/expand): "
+ << (unsigned int)capacity << " - "
+ << (float(numalloc) + float(numexpand))/num_iterations
+ << "(" << float(numalloc)/num_iterations << "/" << float(numexpand)/num_iterations << ")"
+ << std::endl << std::endl;
+ bc::dlmalloc_trim(0);
+}
+
+void print_header()
+{
+ std::cout << "Allocator" << ";" << "Iterations" << ";" << "Size" << ";"
+ << "Capacity" << ";" << "push_back(ns)" << ";" << "Allocator calls" << ";"
+ << "New allocations" << ";" << "Fwd expansions" << std::endl;
+}
+
+int main()
+{
+ #define SINGLE_TEST
+ #ifndef SINGLE_TEST
+ #ifdef NDEBUG
+ unsigned int numit [] = { 1000, 10000, 100000, 1000000 };
+ #else
+ unsigned int numit [] = { 100, 1000, 10000, 100000 };
+ #endif
+ unsigned int numele [] = { 10000, 1000, 100, 10 };
+ #else
+ #ifdef NDEBUG
+ std::size_t numit [] = { 1000 };
+ #else
+ std::size_t numit [] = { 100 };
+ #endif
+ std::size_t numele [] = { 10000 };
+ #endif
+
+ print_header();
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ vector_test_template< bc::vector<MyInt, std::allocator<MyInt> > >(numit[i], numele[i]);
+ vector_test_template< bc::vector<MyInt, bc::allocator<MyInt, 1> > >(numit[i], numele[i]);
+ vector_test_template<bc::vector<MyInt, bc::allocator<MyInt, 2, bc::expand_bwd | bc::expand_fwd> > >(numit[i], numele[i]);
+ vector_test_template<bc::vector<MyInt, bc::allocator<MyInt, 2> > >(numit[i], numele[i]);
+ }
+ return 0;
+}
diff --git a/bench/bench_alloc_shrink_to_fit.cpp b/bench/bench_alloc_shrink_to_fit.cpp
new file mode 100644
index 0000000..687d76d
--- /dev/null
+++ b/bench/bench_alloc_shrink_to_fit.cpp
@@ -0,0 +1,177 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2013. 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)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifdef _MSC_VER
+#pragma warning (disable : 4512)
+#endif
+
+#include <boost/container/allocator.hpp>
+
+#define BOOST_CONTAINER_VECTOR_ALLOC_STATS
+
+#include <boost/container/vector.hpp>
+
+#undef BOOST_CONTAINER_VECTOR_ALLOC_STATS
+
+#include <memory> //std::allocator
+#include <iostream> //std::cout, std::endl
+#include <cassert> //assert
+
+#include <boost/timer/timer.hpp>
+using boost::timer::cpu_timer;
+using boost::timer::cpu_times;
+using boost::timer::nanosecond_type;
+
+namespace bc = boost::container;
+
+typedef std::allocator<int> StdAllocator;
+typedef bc::allocator<int, 2> AllocatorPlusV2;
+typedef bc::allocator<int, 1> AllocatorPlusV1;
+
+template<class Allocator> struct get_allocator_name;
+
+template<> struct get_allocator_name<StdAllocator>
+{ static const char *get() { return "StdAllocator"; } };
+
+template<> struct get_allocator_name<AllocatorPlusV2>
+{ static const char *get() { return "AllocatorPlusV2"; } };
+
+template<> struct get_allocator_name<AllocatorPlusV1>
+{ static const char *get() { return "AllocatorPlusV1"; } };
+
+class MyInt
+{
+ std::size_t int_; //Use a type that will grow on 64 bit machines
+
+ public:
+ MyInt(int i = 0) : int_(i){}
+
+ MyInt(const MyInt &other)
+ : int_(other.int_)
+ {}
+
+ MyInt & operator=(const MyInt &other)
+ {
+ int_ = other.int_;
+ return *this;
+ }
+};
+
+void print_header()
+{
+ std::cout << "Allocator" << ";" << "Iterations" << ";" << "Size" << ";"
+ << "num_shrink" << ";" << "shrink_to_fit(ns)" << std::endl;
+}
+
+template<class Allocator>
+void vector_test_template(unsigned int num_iterations, unsigned int num_elements, bool csv_output)
+{
+ typedef typename Allocator::template rebind<MyInt>::other IntAllocator;
+
+ unsigned int capacity = 0;
+ const std::size_t Step = 5;
+ unsigned int num_shrink = 0;
+ (void)capacity;
+
+ cpu_timer timer;
+ timer.resume();
+
+ #ifndef NDEBUG
+ typedef bc::dtl::integral_constant
+ <unsigned, bc::dtl::version<Allocator>::value> alloc_version;
+ #endif
+
+ for(unsigned int r = 0; r != num_iterations; ++r){
+ bc::vector<MyInt, IntAllocator> v(num_elements);
+ v.reset_alloc_stats();
+ num_shrink = 0;
+ for(unsigned int e = num_elements; e != 0; e -= Step){
+ v.erase(v.end() - Step, v.end());
+ v.shrink_to_fit();
+ assert( (alloc_version::value != 2) || (e == Step) || (v.num_shrink > num_shrink) );
+ num_shrink = v.num_shrink;
+ }
+ assert(v.empty());
+ assert(0 == v.capacity());
+ }
+
+ timer.stop();
+ nanosecond_type nseconds = timer.elapsed().wall;
+
+ if(csv_output){
+ std::cout << get_allocator_name<Allocator>::get()
+ << ";"
+ << num_iterations
+ << ";"
+ << num_elements
+ << ";"
+ << num_shrink
+ << ";"
+ << float(nseconds)/(num_iterations*num_elements)
+ << std::endl;
+ }
+ else{
+ std::cout << std::endl
+ << "Allocator: " << get_allocator_name<Allocator>::get()
+ << std::endl
+ << " num_shrink: " << num_shrink
+ << std::endl
+ << " shrink_to_fit ns: "
+ << float(nseconds)/(num_iterations*num_elements)
+ << std::endl << std::endl;
+ }
+ bc::dlmalloc_trim(0);
+}
+
+int main(int argc, const char *argv[])
+{
+ #define SINGLE_TEST
+ #ifndef SINGLE_TEST
+ #ifdef NDEBUG
+ unsigned int numit [] = { 100, 1000, 10000 };
+ #else
+ unsigned int numit [] = { 10, 100, 1000 };
+ #endif
+ unsigned int numele [] = { 10000, 2000, 500 };
+ #else
+ #ifdef NDEBUG
+ unsigned int numit [] = { 500 };
+ #else
+ unsigned int numit [] = { 50 };
+ #endif
+ unsigned int numele [] = { 2000 };
+ #endif
+
+ bool csv_output = argc == 2 && (strcmp(argv[1], "--csv-output") == 0);
+
+ if(csv_output){
+ print_header();
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ vector_test_template<StdAllocator>(numit[i], numele[i], csv_output);
+ }
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ vector_test_template<AllocatorPlusV1>(numit[i], numele[i], csv_output);
+ }
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ vector_test_template<AllocatorPlusV2>(numit[i], numele[i], csv_output);
+ }
+ }
+ else{
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ std::cout << "\n ----------------------------------- \n"
+ << " Iterations/Elements: " << numit[i] << "/" << numele[i]
+ << "\n ----------------------------------- \n";
+ vector_test_template<StdAllocator>(numit[i], numele[i], csv_output);
+ vector_test_template<AllocatorPlusV1>(numit[i], numele[i], csv_output);
+ vector_test_template<AllocatorPlusV2>(numit[i], numele[i], csv_output);
+ }
+ }
+ return 0;
+}
diff --git a/bench/bench_alloc_stable_vector_burst.cpp b/bench/bench_alloc_stable_vector_burst.cpp
new file mode 100644
index 0000000..29cf1c6
--- /dev/null
+++ b/bench/bench_alloc_stable_vector_burst.cpp
@@ -0,0 +1,290 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2007-2013. 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)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifdef _MSC_VER
+#pragma warning (disable : 4512)
+#pragma warning (disable : 4541)
+#pragma warning (disable : 4673)
+#pragma warning (disable : 4671)
+#pragma warning (disable : 4244)
+#endif
+
+#include <memory> //std::allocator
+#include <iostream> //std::cout, std::endl
+#include <vector> //std::vector
+#include <cstddef> //std::size_t
+#include <cassert> //assert
+
+#include <boost/container/allocator.hpp>
+#include <boost/container/adaptive_pool.hpp>
+#include <boost/container/stable_vector.hpp>
+#include <boost/container/vector.hpp>
+#include <boost/timer/timer.hpp>
+
+using boost::timer::cpu_timer;
+using boost::timer::cpu_times;
+using boost::timer::nanosecond_type;
+
+namespace bc = boost::container;
+
+typedef std::allocator<int> StdAllocator;
+typedef bc::allocator<int, 1> AllocatorPlusV1;
+typedef bc::allocator<int, 2> AllocatorPlusV2;
+typedef bc::adaptive_pool
+ < int
+ , bc::ADP_nodes_per_block
+ , 0//bc::ADP_max_free_blocks
+ , 2
+ , 2> AdPool2PercentV2;
+
+template<class Allocator> struct get_allocator_name;
+
+template<> struct get_allocator_name<StdAllocator>
+{ static const char *get() { return "StdAllocator"; } };
+
+template<> struct get_allocator_name<AllocatorPlusV1>
+{ static const char *get() { return "AllocatorPlusV1"; } };
+
+template<> struct get_allocator_name<AllocatorPlusV2>
+{ static const char *get() { return "AllocatorPlusV2"; } };
+
+template<> struct get_allocator_name<AdPool2PercentV2>
+{ static const char *get() { return "AdPool2PercentV2"; } };
+
+class MyInt
+{
+ int int_;
+
+ public:
+ MyInt(int i = 0) : int_(i){}
+ MyInt(const MyInt &other)
+ : int_(other.int_)
+ {}
+ MyInt & operator=(const MyInt &other)
+ {
+ int_ = other.int_;
+ return *this;
+ }
+};
+
+template<class Allocator>
+struct get_vector
+{
+ typedef bc::vector
+ <MyInt, typename Allocator::template rebind<MyInt>::other> type;
+ static const char *vector_name()
+ {
+ return "vector<MyInt>";
+ }
+};
+
+template<class Allocator>
+struct get_stable_vector
+{
+ typedef bc::stable_vector
+ <MyInt, typename Allocator::template rebind<MyInt>::other> type;
+ static const char *vector_name()
+ {
+ return "stable_vector<MyInt>";
+ }
+};
+
+template<template<class> class GetContainer, class Allocator>
+void stable_vector_test_template(unsigned int num_iterations, unsigned int num_elements, bool csv_output)
+{
+ typedef typename GetContainer<Allocator>::type vector_type;
+ //std::size_t top_capacity = 0;
+ nanosecond_type nseconds;
+ {
+ {
+ vector_type l;
+ cpu_timer timer;
+ timer.resume();
+
+ for(unsigned int r = 0; r != num_iterations; ++r){
+ l.insert(l.end(), num_elements, MyInt(r));
+ }
+
+ timer.stop();
+ nseconds = timer.elapsed().wall;
+
+ if(csv_output){
+ std::cout << get_allocator_name<Allocator>::get()
+ << ";"
+ << GetContainer<Allocator>::vector_name()
+ << ";"
+ << num_iterations
+ << ";"
+ << num_elements
+ << ";"
+ << float(nseconds)/(num_iterations*num_elements)
+ << ";";
+ }
+ else{
+ std::cout << "Allocator: " << get_allocator_name<Allocator>::get()
+ << '\t'
+ << GetContainer<Allocator>::vector_name()
+ << std::endl
+ << " allocation ns: "
+ << float(nseconds)/(num_iterations*num_elements);
+ }
+// top_capacity = l.capacity();
+ //Now preprocess ranges to erase
+ std::vector<typename vector_type::iterator> ranges_to_erase;
+ ranges_to_erase.push_back(l.begin());
+ for(unsigned int r = 0; r != num_iterations; ++r){
+ typename vector_type::iterator next_pos(ranges_to_erase[r]);
+ std::size_t n = num_elements;
+ while(n--){ ++next_pos; }
+ ranges_to_erase.push_back(next_pos);
+ }
+
+ //Measure range erasure function
+ timer.stop();
+ timer.start();
+
+ for(unsigned int r = 0; r != num_iterations; ++r){
+ std::size_t init_pos = (num_iterations-1)-r;
+ l.erase(ranges_to_erase[init_pos], l.end());
+ }
+ timer.stop();
+ nseconds = timer.elapsed().wall;
+ assert(l.empty());
+ }
+ }
+
+ if(csv_output){
+ std::cout << float(nseconds)/(num_iterations*num_elements)
+ << std::endl;
+ }
+ else{
+ std::cout << '\t'
+ << " deallocation ns: "
+ << float(nseconds)/(num_iterations*num_elements)/*
+ << std::endl
+ << " max capacity: "
+ << static_cast<unsigned int>(top_capacity)
+ << std::endl
+ << " remaining cap. "
+ << static_cast<unsigned int>(top_capacity - num_iterations*num_elements)
+ << " (" << (float(top_capacity)/float(num_iterations*num_elements) - 1)*100 << " %)"*/
+ << std::endl << std::endl;
+ }
+ assert(bc::dlmalloc_all_deallocated());
+ bc::dlmalloc_trim(0);
+}
+
+void print_header()
+{
+ std::cout << "Allocator" << ";" << "Iterations" << ";" << "Size" << ";"
+ << "Insertion time(ns)" << ";" << "Erasure time(ns)" << ";"
+ << std::endl;
+}
+
+void stable_vector_operations()
+{
+ {
+ bc::stable_vector<int> a(bc::stable_vector<int>::size_type(5), 4);
+ bc::stable_vector<int> b(a);
+ bc::stable_vector<int> c(a.cbegin(), a.cend());
+ b.insert(b.cend(), 0);
+ c.pop_back();
+ a.assign(b.cbegin(), b.cend());
+ a.assign(c.cbegin(), c.cend());
+ a.assign(1, 2);
+ }
+ {
+ typedef bc::stable_vector<int, std::allocator<int> > stable_vector_t;
+ stable_vector_t a(bc::stable_vector<int>::size_type(5), 4);
+ stable_vector_t b(a);
+ stable_vector_t c(a.cbegin(), a.cend());
+ b.insert(b.cend(), 0);
+ c.pop_back();
+ assert(static_cast<std::size_t>(a.end() - a.begin()) == a.size());
+ a.assign(b.cbegin(), b.cend());
+ assert(static_cast<std::size_t>(a.end() - a.begin()) == a.size());
+ a.assign(c.cbegin(), c.cend());
+ assert(static_cast<std::size_t>(a.end() - a.begin()) == a.size());
+ a.assign(1, 2);
+ assert(static_cast<std::size_t>(a.end() - a.begin()) == a.size());
+ a.reserve(100);
+ assert(static_cast<std::size_t>(a.end() - a.begin()) == a.size());
+ }
+}
+
+int main(int argc, const char *argv[])
+{
+ #define SINGLE_TEST
+ #ifndef SINGLE_TEST
+ #ifdef NDEBUG
+ unsigned int numit [] = { 40, 400, 4000, 40000 };
+ #else
+ unsigned int numit [] = { 4, 40, 400, 4000 };
+ #endif
+ unsigned int numele [] = { 10000, 1000, 100, 10 };
+ #else
+ #ifdef NDEBUG
+ unsigned int numit [] = { 40 };
+ #else
+ unsigned int numit [] = { 4 };
+ #endif
+ unsigned int numele [] = { 10000 };
+ #endif
+
+ //Warning: range erasure is buggy. Vector iterators are not stable, so it is not
+ //possible to cache iterators, but indexes!!!
+
+ bool csv_output = argc == 2 && (strcmp(argv[1], "--csv-output") == 0);
+
+ if(csv_output){
+ print_header();
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ stable_vector_test_template<get_stable_vector, StdAllocator>(numit[i], numele[i], csv_output);
+ }
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ stable_vector_test_template<get_vector, StdAllocator>(numit[i], numele[i], csv_output);
+ }
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ stable_vector_test_template<get_stable_vector, AllocatorPlusV1>(numit[i], numele[i], csv_output);
+ }
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ stable_vector_test_template<get_vector, AllocatorPlusV1>(numit[i], numele[i], csv_output);
+ }
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ stable_vector_test_template<get_stable_vector, AllocatorPlusV2>(numit[i], numele[i], csv_output);
+ }
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ stable_vector_test_template<get_vector, AllocatorPlusV2>(numit[i], numele[i], csv_output);
+ }
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ stable_vector_test_template<get_stable_vector, AdPool2PercentV2>(numit[i], numele[i], csv_output);
+ }
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ stable_vector_test_template<get_vector, AdPool2PercentV2>(numit[i], numele[i], csv_output);
+ }
+ }
+ else{
+ for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
+ std::cout << "\n ----------------------------------- \n"
+ << " Iterations/Elements: " << numit[i] << "/" << numele[i]
+ << "\n ----------------------------------- \n";
+ stable_vector_test_template<get_stable_vector, StdAllocator>(numit[i], numele[i], csv_output);
+ stable_vector_test_template<get_vector, StdAllocator>(numit[i], numele[i], csv_output);
+ stable_vector_test_template<get_stable_vector, AllocatorPlusV1>(numit[i], numele[i], csv_output);
+ stable_vector_test_template<get_vector, AllocatorPlusV1>(numit[i], numele[i], csv_output);
+ stable_vector_test_template<get_stable_vector, AllocatorPlusV2>(numit[i], numele[i], csv_output);
+ stable_vector_test_template<get_vector, AllocatorPlusV2>(numit[i], numele[i], csv_output);
+ stable_vector_test_template<get_stable_vector, AdPool2PercentV2>(numit[i], numele[i], csv_output);
+ stable_vector_test_template<get_vector, AdPool2PercentV2>(numit[i], numele[i], csv_output);
+ }
+ }
+
+ return 0;
+}
diff --git a/bench/bench_flat_multiset.cpp b/bench/bench_flat_multiset.cpp
new file mode 100644
index 0000000..6ee7cca
--- /dev/null
+++ b/bench/bench_flat_multiset.cpp
@@ -0,0 +1,29 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2013-2013. 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)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include "boost/container/set.hpp"
+#include "boost/container/flat_set.hpp"
+#include "bench_set.hpp"
+
+int main()
+{
+ using namespace boost::container;
+
+ fill_range_ints();
+ fill_range_strings();
+
+ //flat_set vs set
+ launch_tests< flat_multiset<int> , multiset<int> >
+ ("flat_multiset<int>", "multiset<int>");
+ launch_tests< flat_multiset<string> , multiset<string> >
+ ("flat_multiset<string>", "multiset<string>");
+
+ return 0;
+}
diff --git a/bench/bench_flat_set.cpp b/bench/bench_flat_set.cpp
new file mode 100644
index 0000000..8f86ba4
--- /dev/null
+++ b/bench/bench_flat_set.cpp
@@ -0,0 +1,29 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2013-2013. 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)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include "boost/container/set.hpp"
+#include "boost/container/flat_set.hpp"
+#include "bench_set.hpp"
+
+int main()
+{
+ using namespace boost::container;
+
+ fill_range_ints();
+ fill_range_strings();
+
+ //flat_set vs set
+ launch_tests< flat_set<int> , set<int> >
+ ("flat_set<int>", "set<int>");
+ launch_tests< flat_set<string> , set<string> >
+ ("flat_set<string>", "set<string>");
+
+ return 0;
+}
diff --git a/bench/bench_set.cpp b/bench/bench_set.cpp
new file mode 100644
index 0000000..890fd35
--- /dev/null
+++ b/bench/bench_set.cpp
@@ -0,0 +1,35 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2013-2013. 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)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include "boost/container/set.hpp"
+#include <set>
+#include "bench_set.hpp"
+
+int main()
+{
+ using namespace boost::container;
+
+ fill_range_ints();
+ fill_range_strings();
+
+ //set vs std::set
+ launch_tests< set<int> , std::set<int> >
+ ("set<int>", "std::set<int>");
+ launch_tests< set<string> , std::set<string> >
+ ("set<string>", "std::set<string>");
+
+ //set(sizeopt) vs set(!sizeopt)
+ launch_tests< set<int>, set<int, std::less<int>, std::allocator<int>, tree_assoc_options< optimize_size<false> >::type > >
+ ("set<int>(sizeopt=true)", "set<int>(sizeopt=false)");
+ launch_tests< set<string>, set<string, std::less<string>, std::allocator<string>, tree_assoc_options< optimize_size<false> >::type > >
+ ("set<string>(sizeopt=true)", "set<string>(sizeopt=false)");
+
+ return 0;
+}
diff --git a/bench/bench_set.hpp b/bench/bench_set.hpp
new file mode 100644
index 0000000..4af500c
--- /dev/null
+++ b/bench/bench_set.hpp
@@ -0,0 +1,479 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2013-2014. 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)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_CONTAINER_BENCH_BENCH_SET_HPP
+#define BOOST_CONTAINER_BENCH_BENCH_SET_HPP
+
+#include <iostream>
+#include <boost/timer/timer.hpp>
+#include <algorithm> //sort
+#include <exception>
+#include <sstream>
+#include <iomanip>
+#include <boost/container/vector.hpp>
+#include <boost/container/string.hpp>
+
+using boost::timer::cpu_timer;
+using boost::timer::cpu_times;
+using boost::timer::nanosecond_type;
+
+static const std::size_t NElements = 1000;
+
+#ifdef NDEBUG
+static const std::size_t NIter = 250;
+#else
+static const std::size_t NIter = 25;
+#endif
+
+void compare_times(cpu_times time_numerator, cpu_times time_denominator){
+ std::cout << ((double)time_numerator.wall/(double)time_denominator.wall) << std::endl;
+ std::cout << "----------------------------------------------" << '\n' << std::endl;
+}
+
+template< class RandomIt >
+void random_shuffle( RandomIt first, RandomIt last )
+{
+ typedef typename boost::container::iterator_traits<RandomIt>::difference_type difference_type;
+ difference_type n = last - first;
+ for (difference_type i = n-1; i > 0; --i) {
+ difference_type j = std::rand() % (i+1);
+ if(j != i) {
+ boost::adl_move_swap(first[i], first[j]);
+ }
+ }
+}
+
+boost::container::vector<int> sorted_unique_range_int;
+boost::container::vector<int> sorted_range_int;
+boost::container::vector<int> random_unique_range_int;
+boost::container::vector<int> random_range_int;
+
+void fill_range_ints()
+{
+ //sorted_unique_range_int
+ sorted_unique_range_int.resize(NElements);
+ for(std::size_t i = 0, max = sorted_unique_range_int.size(); i != max; ++i){
+ sorted_unique_range_int[i] = static_cast<int>(i);
+ }
+ //sorted_range_int
+ sorted_range_int = sorted_unique_range_int;
+ sorted_range_int.insert(sorted_range_int.end(), sorted_unique_range_int.begin(), sorted_unique_range_int.end());
+ std::sort(sorted_range_int.begin(), sorted_range_int.end());
+
+ //random_range_int
+ std::srand(0);
+ random_range_int.assign(sorted_range_int.begin(), sorted_range_int.end());
+ ::random_shuffle(random_range_int.begin(), random_range_int.end());
+ //random_unique_range_int
+ std::srand(0);
+ random_unique_range_int.assign(sorted_unique_range_int.begin(), sorted_unique_range_int.end());
+ ::random_shuffle(random_unique_range_int.begin(), random_unique_range_int.end());
+}
+
+boost::container::vector<boost::container::string> sorted_unique_range_string;
+boost::container::vector<boost::container::string> sorted_range_string;
+boost::container::vector<boost::container::string> random_unique_range_string;
+boost::container::vector<boost::container::string> random_range_string;
+
+void fill_range_strings()
+{
+ boost::container::string model_s;
+ model_s.append(sizeof(boost::container::string), '*');
+
+ //sorted_unique_range_int
+ sorted_unique_range_string.resize(NElements);
+ std::stringstream sstr;
+
+ for(std::size_t i = 0, max = sorted_unique_range_string.size(); i != max; ++i){
+ sstr.str(std::string());
+ sstr << std::setfill('0') << std::setw(10) << i;
+ sorted_unique_range_string[i] = model_s;
+ const std::string &s = sstr.str();
+ sorted_unique_range_string[i].append(s.begin(), s.end());
+ }
+ //sorted_range_string
+ sorted_range_string = sorted_unique_range_string;
+ sorted_range_string.insert(sorted_range_string.end(), sorted_unique_range_string.begin(), sorted_unique_range_string.end());
+ std::sort(sorted_range_string.begin(), sorted_range_string.end());
+
+ //random_range_string
+ std::srand(0);
+ random_range_string.assign(sorted_range_string.begin(), sorted_range_string.end());
+ ::random_shuffle(random_range_string.begin(), random_range_string.end());
+ //random_unique_range_string
+ std::srand(0);
+ random_unique_range_string.assign(sorted_unique_range_string.begin(), sorted_unique_range_string.end());
+ ::random_shuffle(random_unique_range_string.begin(), random_unique_range_string.end());
+}
+
+template<class T>
+struct range_provider;
+
+template<>
+struct range_provider<int>
+{
+ typedef boost::container::vector<int> type;
+
+ static type &sorted_unique()
+ { return sorted_unique_range_int; }
+
+ static type &sorted()
+ { return sorted_range_int; }
+
+ static type &random_unique()
+ { return random_unique_range_int; }
+
+ static type &random()
+ { return random_range_int; }
+};
+
+template<>
+struct range_provider<boost::container::string>
+{
+ typedef boost::container::vector<boost::container::string> type;
+
+ static type &sorted_unique()
+ { return sorted_unique_range_string; }
+
+ static type &sorted()
+ { return sorted_range_string; }
+
+ static type &random_unique()
+ { return random_unique_range_string; }
+
+ static type &random()
+ { return random_range_string; }
+};
+
+template<typename C>
+cpu_times copy_destroy_time(boost::container::vector<typename C::value_type> &unique_range)
+{
+ cpu_timer copy_timer, assign_timer, destroy_timer;
+
+ cpu_timer total_time;
+
+ for(std::size_t i = 0; i != NIter; ++i){
+ {
+ C c(unique_range.begin(), unique_range.end());
+ total_time.resume();
+ copy_timer.resume();
+ C caux(c);
+ copy_timer.stop();
+ assign_timer.resume();
+ c = caux;
+ assign_timer.stop();
+ destroy_timer.resume();
+ }
+ destroy_timer.stop();
+ total_time.stop();
+ }
+ total_time.stop();
+
+ std::cout << " Copy sorted range " << boost::timer::format(copy_timer.elapsed(), boost::timer::default_places, "%ws\n");
+ std::cout << " Assign sorted range " << boost::timer::format(assign_timer.elapsed(), boost::timer::default_places, "%ws\n");
+ std::cout << " Destroy " << boost::timer::format(destroy_timer.elapsed(), boost::timer::default_places, "%ws\n");
+ std::cout << " Total time = " << boost::timer::format(total_time.elapsed(), boost::timer::default_places, "%ws\n") << std::endl;
+ return total_time.elapsed();
+}
+
+template<typename C>
+cpu_times construct_time( boost::container::vector<typename C::value_type> &unique_range
+ , boost::container::vector<typename C::value_type> &range
+ , const char *RangeType)
+{
+ cpu_timer sur_timer, sr_timer;
+
+ cpu_timer total_time;
+
+ for(std::size_t i = 0; i != NIter; ++i){
+ {
+ sur_timer.resume();
+ total_time.resume();
+ C c(unique_range.begin(), unique_range.end());
+ sur_timer.stop();
+ total_time.stop();
+ }
+ {
+ total_time.resume();
+ sr_timer.resume();
+ C c(range.begin(), range.end());
+ sr_timer.stop();
+ total_time.stop();
+ }
+ }
+
+ std::cout << " Construct " << RangeType << " unique_range " << boost::timer::format(sur_timer.elapsed(), boost::timer::default_places, "%ws\n");
+ std::cout << " Construct " << RangeType << " range " << boost::timer::format(sr_timer.elapsed(), boost::timer::default_places, "%ws\n");
+ std::cout << " Total time = " << boost::timer::format(total_time.elapsed(), boost::timer::default_places, "%ws\n") << std::endl;
+ return total_time.elapsed();
+}
+
+template<typename C>
+cpu_times insert_time( boost::container::vector<typename C::value_type> &unique_range
+ , boost::container::vector<typename C::value_type> &range
+ , const char *RangeType)
+{
+ cpu_timer ur_timer,r_timer;
+ ur_timer.stop();r_timer.stop();
+
+ cpu_timer total_time;
+ total_time.resume();
+
+ for(std::size_t i = 0; i != NIter; ++i){
+ {
+ total_time.resume();
+ ur_timer.resume();
+ C c;
+ c.insert(unique_range.begin(), unique_range.end());
+ ur_timer.stop();
+ total_time.stop();
+ }
+ {
+ total_time.resume();
+ r_timer.resume();
+ C c;
+ c.insert(range.begin(), range.end());
+ r_timer.stop();
+ total_time.stop();
+ }
+ }
+
+ std::cout << " Insert " << RangeType << " unique_range " << boost::timer::format(ur_timer.elapsed(), boost::timer::default_places, "%ws\n");
+ std::cout << " Insert " << RangeType << " range " << boost::timer::format(r_timer.elapsed(), boost::timer::default_places, "%ws\n");
+ std::cout << " Total time = " << boost::timer::format(total_time.elapsed(), boost::timer::default_places, "%ws\n") << std::endl;
+ return total_time.elapsed();
+}
+
+template<typename Iterator>
+bool check_not_end(boost::container::vector<Iterator> &iterators, Iterator itend, std::size_t number_of_ends = 0)
+{
+ std::size_t end_count = 0;
+ for(std::size_t i = 0, max = iterators.size(); i != max; ++i){
+ if(iterators[i] == itend && (++end_count > number_of_ends) )
+ return false;
+ }
+ return true;
+}
+
+template<typename Iterator>
+bool check_all_not_empty(boost::container::vector< std::pair<Iterator, Iterator > > &iterator_pairs)
+{
+ for(std::size_t i = 0, max = iterator_pairs.size(); i != max; ++i){
+ if(iterator_pairs[i].first == iterator_pairs[i].second)
+ return false;
+ }
+ return true;
+}
+
+template<typename C>
+cpu_times search_time(boost::container::vector<typename C::value_type> &unique_range, const char *RangeType)
+{
+ cpu_timer find_timer, lower_timer, upper_timer, equal_range_timer, count_timer;
+
+ C c(unique_range.begin(), unique_range.end());
+
+ cpu_timer total_time;
+ total_time.resume();
+
+ boost::container::vector<typename C::iterator> v_it(NElements);
+ boost::container::vector< std::pair<typename C::iterator, typename C::iterator> > v_itp(NElements);
+
+ for(std::size_t i = 0; i != NIter; ++i){
+ //Find
+ {
+ find_timer.resume();
+ for(std::size_t rep = 0; rep != 2; ++rep)
+ for(std::size_t i = 0, max = unique_range.size(); i != max; ++i){
+ v_it[i] = c.find(unique_range[i]);
+ }
+ find_timer.stop();
+ if(!check_not_end(v_it, c.end())){
+ std::cout << "ERROR! find all elements not found" << std::endl;
+ }
+ }
+ //Lower
+ {
+ lower_timer.resume();
+ for(std::size_t rep = 0; rep != 2; ++rep)
+ for(std::size_t i = 0, max = unique_range.size(); i != max; ++i){
+ v_it[i] = c.lower_bound(unique_range[i]);
+ }
+ lower_timer.stop();
+ if(!check_not_end(v_it, c.end())){
+ std::cout << "ERROR! lower_bound all elements not found" << std::endl;
+ }
+ }
+ //Upper
+ {
+ upper_timer.resume();
+ for(std::size_t rep = 0; rep != 2; ++rep)
+ for(std::size_t i = 0, max = unique_range.size(); i != max; ++i){
+ v_it[i] = c.upper_bound(unique_range[i]);
+ }
+ upper_timer.stop();
+ if(!check_not_end(v_it, c.end(), 1u)){
+ std::cout << "ERROR! upper_bound all elements not found" << std::endl;
+ }
+ }
+ //Equal
+ {
+ equal_range_timer.resume();
+ for(std::size_t rep = 0; rep != 2; ++rep)
+ for(std::size_t i = 0, max = unique_range.size(); i != max; ++i){
+ v_itp[i] = c.equal_range(unique_range[i]);
+ }
+ equal_range_timer.stop();
+ if(!check_all_not_empty(v_itp)){
+ std::cout << "ERROR! equal_range all elements not found" << std::endl;
+ }
+ }
+ //Count
+ {
+ std::size_t count = 0;
+ count_timer.resume();
+ for(std::size_t rep = 0; rep != 2; ++rep)
+ for(std::size_t i = 0, max = unique_range.size(); i != max; ++i){
+ count += c.count(unique_range[i]);
+ }
+ count_timer.stop();
+ if(count/2 != c.size()){
+ std::cout << "ERROR! count all elements not found" << std::endl;
+ }
+ }
+ }
+ total_time.stop();
+
+ std::cout << " Find " << RangeType << " " << boost::timer::format(find_timer.elapsed(), boost::timer::default_places, "%ws\n");
+ std::cout << " Lower Bound " << RangeType << " " << boost::timer::format(lower_timer.elapsed(), boost::timer::default_places, "%ws\n");
+ std::cout << " Upper Bound " << RangeType << " " << boost::timer::format(upper_timer.elapsed(), boost::timer::default_places, "%ws\n");
+ std::cout << " Equal Range " << RangeType << " " << boost::timer::format(equal_range_timer.elapsed(), boost::timer::default_places, "%ws\n");
+ std::cout << " Count " << RangeType << " " << boost::timer::format(count_timer.elapsed(), boost::timer::default_places, "%ws\n");
+ std::cout << " Total time = " << boost::timer::format(total_time.elapsed(), boost::timer::default_places, "%ws\n") << std::endl;
+ return total_time.elapsed();
+}
+
+template<typename C>
+void extensions_time(boost::container::vector<typename C::value_type> &sorted_unique_range)
+{
+ cpu_timer sur_timer,sur_opt_timer;
+ sur_timer.stop();sur_opt_timer.stop();
+
+ for(std::size_t i = 0; i != NIter; ++i){
+ {
+ sur_timer.resume();
+ C c(sorted_unique_range.begin(), sorted_unique_range.end());
+ sur_timer.stop();
+ }
+ {
+ sur_opt_timer.resume();
+ C c(boost::container::ordered_unique_range, sorted_unique_range.begin(), sorted_unique_range.end());
+ sur_opt_timer.stop();
+ }
+
+ }
+ std::cout << " Construct sorted_unique_range " << boost::timer::format(sur_timer.elapsed(), boost::timer::default_places, "%ws\n");
+ std::cout << " Construct sorted_unique_range (extension) " << boost::timer::format(sur_opt_timer.elapsed(), boost::timer::default_places, "%ws\n");
+ std::cout << "Extension/Standard: ";
+ compare_times(sur_opt_timer.elapsed(), sur_timer.elapsed());
+}
+
+template<class BoostClass, class StdClass>
+void launch_tests(const char *BoostContName, const char *StdContName)
+{
+ typedef range_provider<typename BoostClass::value_type> get_range_t;
+ try {
+ std::cout << "**********************************************" << '\n';
+ std::cout << "**********************************************" << '\n';
+ std::cout << '\n';
+ std::cout << BoostContName << " .VS " << StdContName << '\n';
+ std::cout << '\n';
+ std::cout << "**********************************************" << '\n';
+ std::cout << "**********************************************" << '\n' << std::endl;
+ {
+ std::cout << "Copy/Assign/Destroy benchmark:" << BoostContName << std::endl;
+ cpu_times boost_set_time = copy_destroy_time< BoostClass >(get_range_t::sorted_unique());
+
+ std::cout << "Copy/Assign/Destroy benchmark:" << StdContName << std::endl;
+ cpu_times std_set_time = copy_destroy_time< StdClass >(get_range_t::sorted_unique());
+
+ std::cout << BoostContName << "/" << StdContName << ": ";
+ compare_times(boost_set_time, std_set_time);
+ }
+ {
+ std::cout << "Ordered construct benchmark:" << BoostContName << std::endl;
+ cpu_times boost_set_time = construct_time< BoostClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");
+
+ std::cout << "Ordered construct benchmark:" << StdContName << std::endl;
+ cpu_times std_set_time = construct_time< StdClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");;
+
+ std::cout << BoostContName << "/" << StdContName << ": ";
+ compare_times(boost_set_time, std_set_time);
+ }
+ {
+ std::cout << "Random construct benchmark:" << BoostContName << std::endl;
+ cpu_times boost_set_time = construct_time< BoostClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");
+
+ std::cout << "Random construct benchmark:" << StdContName << std::endl;
+ cpu_times std_set_time = construct_time< StdClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");;
+
+ std::cout << BoostContName << "/" << StdContName << ": ";
+ compare_times(boost_set_time, std_set_time);
+ }
+ {
+ std::cout << "Ordered Insert benchmark:" << BoostContName << std::endl;
+ cpu_times boost_set_time = insert_time< BoostClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");
+
+ std::cout << "Ordered Insert benchmark:" << StdContName << std::endl;
+ cpu_times std_set_time = insert_time< StdClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");
+
+ std::cout << BoostContName << "/" << StdContName << ": ";
+ compare_times(boost_set_time, std_set_time);
+ }
+ {
+ std::cout << "Random Insert benchmark:" << BoostContName << std::endl;
+ cpu_times boost_set_time = insert_time< BoostClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");
+
+ std::cout << "Random Insert benchmark:" << StdContName << std::endl;
+ cpu_times std_set_time = insert_time< StdClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");
+
+ std::cout << BoostContName << "/" << StdContName << ": ";
+ compare_times(boost_set_time, std_set_time);
+ }
+ {
+ std::cout << "Ordered Search benchmark:" << BoostContName << std::endl;
+ cpu_times boost_set_time = search_time< BoostClass >(get_range_t::sorted_unique(), "(ord)");
+
+ std::cout << "Ordered Search benchmark:" << StdContName << std::endl;
+ cpu_times std_set_time = search_time< StdClass >(get_range_t::sorted_unique(), "(ord)");
+
+ std::cout << BoostContName << "/" << StdContName << ": ";
+ compare_times(boost_set_time, std_set_time);
+ }
+ {
+ std::cout << "Random Search benchmark:" << BoostContName << std::endl;
+ cpu_times boost_set_time = search_time< BoostClass >(get_range_t::random_unique(), "(rnd)");
+
+ std::cout << "Random Search benchmark:" << StdContName << std::endl;
+ cpu_times std_set_time = search_time< StdClass >(get_range_t::random_unique(), "(rnd)");
+
+ std::cout << BoostContName << "/" << StdContName << ": ";
+ compare_times(boost_set_time, std_set_time);
+ }
+ {
+ std::cout << "Extensions benchmark:" << BoostContName << std::endl;
+ extensions_time< BoostClass >(get_range_t::sorted_unique());
+ }
+
+ }catch(std::exception e){
+ std::cout << e.what();
+ }
+}
+
+#endif //#ifndef BOOST_CONTAINER_BENCH_BENCH_SET_HPP
diff --git a/bench/bench_set_adaptive_pool.cpp b/bench/bench_set_adaptive_pool.cpp
new file mode 100644
index 0000000..dc5f476
--- /dev/null
+++ b/bench/bench_set_adaptive_pool.cpp
@@ -0,0 +1,34 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2013-2013. 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)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+//Enable checks in debug mode
+#ifndef NDEBUG
+#define BOOST_CONTAINER_ADAPTIVE_NODE_POOL_CHECK_INVARIANTS
+#endif
+
+#include "bench_set.hpp"
+#include <boost/container/set.hpp>
+#include <boost/container/allocator.hpp>
+#include <boost/container/adaptive_pool.hpp>
+
+int main()
+{
+ using namespace boost::container;
+
+ fill_range_ints();
+ fill_range_strings();
+
+ //set<..., adaptive_pool> vs. set
+ launch_tests< set<int, std::less<int>, private_adaptive_pool<int> >, set<int> >
+ ("set<int, ..., private_adaptive_pool<int>", "set<int>");
+ launch_tests< set<string, std::less<string>, private_adaptive_pool<string> >, set<string> >
+ ("set<string, ..., private_adaptive_pool<string>", "set<string>");
+
+ return 0;
+}
diff --git a/bench/bench_set_alloc_v2.cpp b/bench/bench_set_alloc_v2.cpp
new file mode 100644
index 0000000..9c2fb9b
--- /dev/null
+++ b/bench/bench_set_alloc_v2.cpp
@@ -0,0 +1,29 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2013-2013. 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)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include "bench_set.hpp"
+#include <boost/container/set.hpp>
+#include <boost/container/allocator.hpp>
+
+int main()
+{
+ using namespace boost::container;
+
+ fill_range_ints();
+ fill_range_strings();
+
+ //set<..., version_2> vs. set
+ launch_tests< set<int, std::less<int>, allocator<int> >, set<int> >
+ ("set<int, ..., allocator<int>", "set<int>");
+ launch_tests< set<string, std::less<string>, allocator<string> >, set<string> >
+ ("set<string, ..., allocator<string>", "set<string>");
+
+ return 0;
+}
diff --git a/bench/bench_set_avl.cpp b/bench/bench_set_avl.cpp
new file mode 100644
index 0000000..6d0d77d
--- /dev/null
+++ b/bench/bench_set_avl.cpp
@@ -0,0 +1,38 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2013-2013. 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)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include "boost/container/set.hpp"
+#include <set>
+
+#include "bench_set.hpp"
+
+int main()
+{
+ using namespace boost::container;
+
+ fill_range_ints();
+ fill_range_strings();
+
+ //set(AVL) vs set(RB)
+ launch_tests< set<int, std::less<int>, std::allocator<int>, tree_assoc_options< tree_type<avl_tree> >::type >, set<int> >
+ ("set<int>(AVL)", "set<int>(RB)");
+ launch_tests< set<string, std::less<string>, std::allocator<string>, tree_assoc_options< tree_type<avl_tree> >::type >, set<string> >
+ ("set<string>(AVL)", "set<string>(RB)");
+
+ //set(AVL,sizeopt) vs set(AVL,!sizeopt)
+ launch_tests< set<int, std::less<int>, std::allocator<int>, tree_assoc_options< tree_type<avl_tree> >::type >
+ , set<int, std::less<int>, std::allocator<int>, tree_assoc_options< tree_type<avl_tree>, optimize_size<false> >::type > >
+ ("set<int>(AVL,sizeopt=true)", "set<int>(AVL,sizeopt=false)");
+ launch_tests< set<string, std::less<string>, std::allocator<string>, tree_assoc_options< tree_type<avl_tree> >::type >
+ , set<string, std::less<string>, std::allocator<string>, tree_assoc_options< tree_type<avl_tree>, optimize_size<false> >::type > >
+ ("set<string>(AVL,sizeopt=true)", "set<string>(AVL,sizeopt=false)");
+
+ return 0;
+}
diff --git a/bench/bench_set_multi.cpp b/bench/bench_set_multi.cpp
new file mode 100644
index 0000000..a01dbc9
--- /dev/null
+++ b/bench/bench_set_multi.cpp
@@ -0,0 +1,30 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2013-2013. 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)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include "boost/container/set.hpp"
+#include <set>
+
+#include "bench_set.hpp"
+
+int main()
+{
+ using namespace boost::container;
+
+ fill_range_ints();
+ fill_range_strings();
+
+ //multiset vs std::multiset
+ launch_tests< multiset<int> , std::multiset<int> >
+ ("multiset<int>", "std::multiset<int>");
+ launch_tests< multiset<string> , std::multiset<string> >
+ ("multiset<string>", "std::multiset<string>");
+
+ return 0;
+}
diff --git a/bench/bench_set_sg.cpp b/bench/bench_set_sg.cpp
new file mode 100644
index 0000000..c988438
--- /dev/null
+++ b/bench/bench_set_sg.cpp
@@ -0,0 +1,28 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2013-2013. 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)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include "boost/container/set.hpp"
+#include "bench_set.hpp"
+
+int main()
+{
+ using namespace boost::container;
+
+ fill_range_ints();
+ fill_range_strings();
+
+ //set(RB) vs set(SG)
+ launch_tests< set<int, std::less<int>, std::allocator<int>, tree_assoc_options< tree_type<scapegoat_tree> >::type >, set<int> >
+ ("set<int>(SG)", "set<int>(RB)");
+ launch_tests< set<string, std::less<string>, std::allocator<string>, tree_assoc_options< tree_type<scapegoat_tree> >::type >, set<string> >
+ ("set<string>(SG)", "set<string>(RB)");
+
+ return 0;
+}
diff --git a/bench/bench_set_sp.cpp b/bench/bench_set_sp.cpp
new file mode 100644
index 0000000..0f86ed4
--- /dev/null
+++ b/bench/bench_set_sp.cpp
@@ -0,0 +1,28 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2013-2013. 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)
+//
+// See http://www.boost.org/libs/container for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include "boost/container/set.hpp"
+#include "bench_set.hpp"
+
+int main()
+{
+ using namespace boost::container;
+
+ fill_range_ints();
+ fill_range_strings();
+
+ //set(RB) vs set(SP)
+ launch_tests< set<int, std::less<int>, std::allocator<int>, tree_assoc_options< tree_type<splay_tree> >::type >, set<int> >
+ ("set<int>(SP)", "set<int>(RB)");
+ launch_tests< set<string, std::less<string>, std::allocator<string>, tree_assoc_options< tree_type<splay_tree> >::type >, set<string> >
+ ("set<string>(SP)", "set<string>(RB)");
+
+ return 0;
+}
diff --git a/bench/bench_static_vector.cpp b/bench/bench_static_vector.cpp
new file mode 100644
index 0000000..4553dc7
--- /dev/null
+++ b/bench/bench_static_vector.cpp
@@ -0,0 +1,144 @@
+// benchmark based on: http://cpp-next.com/archive/2010/10/howards-stl-move-semantics-benchmark/
+//
+// @file bench_static_vector.cpp
+// @date Aug 14, 2011
+// @author Andrew Hundt <ATHundt@gmail.com>
+//
+// (C) Copyright 2011-2013 Andrew Hundt <ATHundt@gmail.com>
+// (C) Copyright 2013-2013 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)
+//
+// @brief varray_benchmark.cpp compares the performance of boost::container::varray to boost::container::vector
+
+#include "varray.hpp"
+#include "boost/container/vector.hpp"
+#include "boost/container/static_vector.hpp"
+#include "../test/movable_int.hpp"
+#include <vector>
+#include <iostream>
+#include <boost/timer/timer.hpp>
+#include <algorithm>
+#include <exception>
+
+using boost::timer::cpu_timer;
+using boost::timer::cpu_times;
+using boost::timer::nanosecond_type;
+
+static const std::size_t N = 500;
+
+#ifdef NDEBUG
+static const std::size_t Iter = 50;
+#else
+static const std::size_t Iter = 5;
+#endif
+
+//#define BENCH_SIMPLE_CONSTRUCTION
+//#define BENCH_TRIVIAL_TYPE
+
+#ifdef BENCH_TRIVIAL_TYPE
+typedef std::size_t basic_type_t;
+#else
+typedef boost::container::test::copyable_int basic_type_t;
+#endif
+
+template<typename T>
+T &get_set(std::size_t)
+{
+ #ifdef BENCH_SIMPLE_CONSTRUCTION
+ T &t = *new T(N);
+ for (std::size_t i = 0; i < N; ++i)
+ t[i] = basic_type_t(std::rand());
+ #else
+ T &t = *new T;
+ t.reserve(N);
+ for (std::size_t i = 0; i < N; ++i)
+ t.push_back(basic_type_t(std::rand()));
+ #endif
+ return t;
+}
+
+template<typename T>
+T &generate()
+{
+ T &v = *new T;
+ v.reserve(N);
+
+ for (std::size_t i = 0; i < N; ++i){
+ typename T::reference r = get_set<typename T::value_type>(i);
+ v.push_back(boost::move(r));
+ delete &r;
+ }
+ return v;
+}
+
+template<typename T>
+cpu_times time_it()
+{
+ cpu_timer sortTime,rotateTime,destructionTime;
+ sortTime.stop();rotateTime.stop();destructionTime.stop();
+ cpu_timer totalTime, constructTime;
+ std::srand (0);
+ for(std::size_t i = 0; i< Iter; ++i){
+ constructTime.resume();
+ {
+ T &v = generate<T>();
+ constructTime.stop();
+ sortTime.resume();
+ std::sort(v.begin(), v.end());
+ sortTime.stop();
+ rotateTime.resume();
+ std::rotate(v.begin(), v.begin() + v.size()/2, v.end());
+ rotateTime.stop();
+ destructionTime.resume();
+ delete &v;
+ }
+ destructionTime.stop();
+ }
+ totalTime.stop();
+ std::cout << " construction took " << boost::timer::format(constructTime.elapsed(), 6, "%ws wall, %ts CPU (%p%)\n");
+ std::cout << " sort took " << boost::timer::format(sortTime.elapsed(), 6, "%ws wall, %ts CPU (%p%)\n");
+ std::cout << " rotate took " << boost::timer::format(rotateTime.elapsed(), 6, "%ws wall, %ts CPU (%p%)\n");
+ std::cout << " destruction took " << boost::timer::format(destructionTime.elapsed(), 6, "%ws wall, %ts CPU (%p%)\n");
+ std::cout << " Total time = " << boost::timer::format(totalTime.elapsed(), 6, "%ws wall, %ts CPU (%p%)\n") << std::endl;
+ return totalTime.elapsed();
+}
+
+void compare_times(cpu_times time_numerator, cpu_times time_denominator){
+ std::cout
+ << "\n wall = " << ((double)time_numerator.wall/(double)time_denominator.wall)
+ << "\n (user+sys) = " << ((double)(time_numerator.system+time_numerator.user)/(double)(time_denominator.system+time_denominator.user)) << "\n\n";
+}
+
+int main()
+{
+ try {
+ std::cout << "N = " << N << " Iter = " << Iter << "\n\n";
+
+ std::cout << "varray benchmark:" << std::endl;
+ cpu_times time_varray = time_it<boost::container::varray<boost::container::varray<basic_type_t,N>,N > >();
+
+ std::cout << "boost::container::static_vector benchmark" << std::endl;
+ cpu_times time_boost_static_vector = time_it<boost::container::static_vector<boost::container::static_vector<basic_type_t,N>,N > >();
+
+ std::cout << "boost::container::vector benchmark" << std::endl;
+ cpu_times time_boost_vector = time_it<boost::container::vector<boost::container::vector<basic_type_t> > >();
+
+ std::cout << "std::vector benchmark" << std::endl;
+ cpu_times time_standard_vector = time_it<std::vector<std::vector<basic_type_t> > >();
+
+ std::cout << "varray/boost::container::vector total time comparison:";
+ compare_times(time_varray, time_boost_vector);
+
+ std::cout << "varray/boost::container::static_vector total time comparison:";
+ compare_times(time_varray, time_boost_static_vector);
+
+ std::cout << "varray/std::vector total time comparison:";
+ compare_times(time_varray,time_standard_vector);
+ }catch(std::exception e){
+ std::cout << e.what();
+ }
+ return 0;
+}
diff --git a/bench/detail/varray.hpp b/bench/detail/varray.hpp
new file mode 100644
index 0000000..ca29c14
--- /dev/null
+++ b/bench/detail/varray.hpp
@@ -0,0 +1,2242 @@
+// Boost.Container varray
+//
+// Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
+// Copyright (c) 2011-2013 Andrew Hundt.
+// Copyright (c) 2014-2014 Ion Gaztanaga
+//
+// Use, modification and distribution is subject to 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)
+
+#ifndef BOOST_CONTAINER_DETAIL_VARRAY_HPP
+#define BOOST_CONTAINER_DETAIL_VARRAY_HPP
+
+#ifndef BOOST_CONFIG_HPP
+# include <boost/config.hpp>
+#endif
+
+#if defined(BOOST_HAS_PRAGMA_ONCE)
+# pragma once
+#endif
+
+#include <boost/container/detail/config_begin.hpp>
+#include <boost/container/detail/workaround.hpp>
+
+#include <boost/container/detail/addressof.hpp>
+#include <boost/container/detail/algorithm.hpp> //algo_equal(), algo_lexicographical_compare
+#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
+#include <boost/move/detail/fwd_macros.hpp>
+#endif
+#include <boost/container/detail/iterator.hpp>
+#include <boost/container/detail/iterators.hpp>
+#include <boost/container/detail/mpl.hpp>
+#include <boost/container/detail/type_traits.hpp>
+#include <boost/move/adl_move_swap.hpp> //adl_move_swap
+
+
+#include "varray_util.hpp"
+
+#include <boost/assert.hpp>
+#include <boost/config.hpp>
+
+#include <boost/static_assert.hpp>
+
+#ifndef BOOST_NO_EXCEPTIONS
+#include <stdexcept>
+#endif // BOOST_NO_EXCEPTIONS
+
+
+/**
+ * @defgroup varray_non_member varray non-member functions
+ */
+
+namespace boost { namespace container { namespace dtl {
+
+// Forward declaration
+template <typename Value, std::size_t Capacity, typename Strategy>
+class varray;
+
+namespace strategy {
+
+// TODO: Improve error messages
+// possibly include N in the strategy, and provide size as an optoinal allocate_failed parameter?
+// Example of current error with reserve(4) when capacity is 3:
+// "boost/container/varray.hpp(66): size can't exceed the capacity"
+// Could say
+// "cannot reserve(4) due to fixed capacity of 3 elements"
+
+//! @brief The default strategy.
+//!
+//! @tparam Value Type of element stored in the container.
+template <typename Value>
+struct def
+{
+ typedef Value value_type;
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
+ typedef Value* pointer;
+ typedef const Value* const_pointer;
+ typedef Value& reference;
+ typedef const Value& const_reference;
+
+ static void allocate_failed()
+ {
+ BOOST_ASSERT_MSG(false, "size can't exceed the capacity");
+ }
+};
+
+//! @brief The strategy adapting info from passed Allocator.
+//!
+//! This strategy defines the same types that are defined in the Allocator.
+//!
+//! @tparam Allocator The Allocator which will be adapted.
+template <typename Allocator>
+struct allocator_adaptor
+{
+ typedef typename Allocator::value_type value_type;
+ typedef typename Allocator::size_type size_type;
+ typedef typename Allocator::difference_type difference_type;
+ typedef typename Allocator::pointer pointer;
+ typedef typename Allocator::const_pointer const_pointer;
+ typedef typename Allocator::reference reference;
+ typedef typename Allocator::const_reference const_reference;
+
+ static void allocate_failed()
+ {
+ BOOST_ASSERT_MSG(false, "size can't exceed the capacity");
+ }
+};
+
+} // namespace strategy
+
+struct varray_error_handler
+{
+ template <typename V, std::size_t Capacity, typename S>
+ static void check_capacity(varray<V, Capacity, S> const&, std::size_t s)
+ {
+ if ( Capacity < s )
+ S::allocate_failed();
+ }
+
+ template <typename V, std::size_t C, typename S>
+ static void check_at(varray<V, C, S> const& v,
+ typename varray<V, C, S>::size_type i)
+ {
+ (void)v;
+ (void)i;
+// TODO - use BOOST_THROW_EXCEPTION here?
+#ifndef BOOST_NO_EXCEPTIONS
+ if ( v.size() <= i )
+ throw std::out_of_range("index out of bounds");
+#else // BOOST_NO_EXCEPTIONS
+ BOOST_ASSERT_MSG(i < v.size(), "index out of bounds");
+#endif // BOOST_NO_EXCEPTIONS
+ }
+
+ template <typename V, std::size_t C, typename S>
+ static void check_operator_brackets(varray<V, C, S> const& v,
+ typename varray<V, C, S>::size_type i)
+ {
+ (void)v;
+ (void)i;
+ BOOST_ASSERT_MSG(i < v.size(), "index out of bounds");
+ }
+
+ template <typename V, std::size_t C, typename S>
+ static void check_empty(varray<V, C, S> const& v)
+ {
+ (void)v;
+ BOOST_ASSERT_MSG(0 < v.size(), "the container is empty");
+ }
+
+ template <typename V, std::size_t C, typename S>
+ static void check_iterator_end_neq(varray<V, C, S> const& v,
+ typename varray<V, C, S>::const_iterator position)
+ {
+ (void)v;
+ (void)position;
+ BOOST_ASSERT_MSG(v.begin() <= position && position < v.end(), "iterator out of bounds");
+ }
+
+ template <typename V, std::size_t C, typename S>
+ static void check_iterator_end_eq(varray<V, C, S> const& v,
+ typename varray<V, C, S>::const_iterator position)
+ {
+ (void)v;
+ (void)position;
+ BOOST_ASSERT_MSG(v.begin() <= position && position <= v.end(), "iterator out of bounds");
+ }
+};
+
+template <typename Value, std::size_t Capacity, typename Strategy>
+struct varray_traits
+{
+ typedef typename Strategy::value_type value_type;
+ typedef typename Strategy::size_type size_type;
+ typedef typename Strategy::difference_type difference_type;
+ typedef typename Strategy::pointer pointer;
+ typedef typename Strategy::const_pointer const_pointer;
+ typedef typename Strategy::reference reference;
+ typedef typename Strategy::const_reference const_reference;
+
+ typedef varray_error_handler error_handler;
+
+ typedef false_type use_memop_in_swap_and_move;
+ typedef false_type use_optimized_swap;
+ typedef false_type disable_trivial_init;
+};
+
+/**
+ * @brief A variable-size array container with fixed capacity.
+ *
+ * varray is a sequence container like boost::container::vector with contiguous storage that can
+ * change in size, along with the static allocation, low overhead, and fixed capacity of boost::array.
+ *
+ * A varray is a sequence that supports random access to elements, constant time insertion and
+ * removal of elements at the end, and linear time insertion and removal of elements at the beginning or
+ * in the middle. The number of elements in a varray may vary dynamically up to a fixed capacity
+ * because elements are stored within the object itself similarly to an array. However, objects are
+ * initialized as they are inserted into varray unlike C arrays or std::array which must construct
+ * all elements on instantiation. The behavior of varray enables the use of statically allocated
+ * elements in cases with complex object lifetime requirements that would otherwise not be trivially
+ * possible.
+ *
+ * @par Error Handling
+ * Insertion beyond the capacity and out of bounds errors result in undefined behavior unless
+ * otherwise specified. In this respect if size() == capacity(), then varray::push_back()
+ * behaves like std::vector pop_front() if size() == empty(). The reason for this difference
+ * is because unlike vectors, varray does not perform allocation.
+ *
+ * @par Advanced Usage
+ * Error handling behavior can be modified to more closely match std::vector exception behavior
+ * when exceeding bounds by providing an alternate Strategy and varray_traits instantiation.
+ *
+ * @tparam Value The type of element that will be stored.
+ * @tparam Capacity The maximum number of elements varray can store, fixed at compile time.
+ * @tparam Strategy Defines the public typedefs and error handlers,
+ * implements StaticVectorStrategy and has some similarities
+ * to an Allocator.
+ */
+template <typename Value, std::size_t Capacity, typename Strategy = strategy::def<Value> >
+class varray
+{
+ typedef dtl::varray_traits<
+ Value, Capacity, Strategy
+ > vt;
+
+ typedef typename vt::error_handler errh;
+ typedef typename aligned_storage<
+ sizeof(Value[Capacity]),
+ boost::container::dtl::alignment_of<Value[Capacity]>::value
+ >::type aligned_storage_type;
+
+ template <typename V, std::size_t C, typename S>
+ friend class varray;
+
+ BOOST_COPYABLE_AND_MOVABLE(varray)
+
+#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
+public:
+ template <std::size_t C, typename S>
+ varray & operator=(varray<Value, C, S> & sv)
+ {
+ typedef varray<Value, C, S> other;
+ this->operator=(static_cast<const ::boost::rv<other> &>(const_cast<const other &>(sv)));
+ return *this;
+ }
+#endif
+
+public:
+ //! @brief The type of elements stored in the container.
+ typedef typename vt::value_type value_type;
+ //! @brief The unsigned integral type used by the container.
+ typedef typename vt::size_type size_type;
+ //! @brief The pointers difference type.
+ typedef typename vt::difference_type difference_type;
+ //! @brief The pointer type.
+ typedef typename vt::pointer pointer;
+ //! @brief The const pointer type.
+ typedef typename vt::const_pointer const_pointer;
+ //! @brief The value reference type.
+ typedef typename vt::reference reference;
+ //! @brief The value const reference type.
+ typedef typename vt::const_reference const_reference;
+
+ //! @brief The iterator type.
+ typedef pointer iterator;
+ //! @brief The const iterator type.
+ typedef const_pointer const_iterator;
+ //! @brief The reverse iterator type.
+ typedef boost::container::reverse_iterator<iterator> reverse_iterator;
+ //! @brief The const reverse iterator.
+ typedef boost::container::reverse_iterator<const_iterator> const_reverse_iterator;
+
+ //! @brief The type of a strategy used by the varray.
+ typedef Strategy strategy_type;
+
+ //! @brief Constructs an empty varray.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ varray()
+ : m_size(0)
+ {}
+
+ //! @pre <tt>count <= capacity()</tt>
+ //!
+ //! @brief Constructs a varray containing count value initialized Values.
+ //!
+ //! @param count The number of values which will be contained in the container.
+ //!
+ //! @par Throws
+ //! If Value's value initialization throws.
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ explicit varray(size_type count)
+ : m_size(0)
+ {
+ this->resize(count); // may throw
+ }
+
+ //! @pre <tt>count <= capacity()</tt>
+ //!
+ //! @brief Constructs a varray containing count copies of value.
+ //!
+ //! @param count The number of copies of a values that will be contained in the container.
+ //! @param value The value which will be used to copy construct values.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor throws.
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ varray(size_type count, value_type const& value)
+ : m_size(0)
+ {
+ this->resize(count, value); // may throw
+ }
+
+ //! @pre
+ //! @li <tt>distance(first, last) <= capacity()</tt>
+ //! @li Iterator must meet the \c ForwardIterator.
+ //!
+ //! @brief Constructs a varray containing copy of a range <tt>[first, last)</tt>.
+ //!
+ //! @param first The iterator to the first element in range.
+ //! @param last The iterator to the one after the last element in range.
+ //!
+ //! @par Throws
+ //! If Value's constructor taking a dereferenced Iterator throws.
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ template <typename Iterator>
+ varray(Iterator first, Iterator last)
+ : m_size(0)
+ {
+ this->assign(first, last); // may throw
+ }
+
+ //! @brief Constructs a copy of other varray.
+ //!
+ //! @param other The varray which content will be copied to this one.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ varray(varray const& other)
+ : m_size(other.size())
+ {
+ namespace sv = varray_detail;
+ sv::uninitialized_copy(other.begin(), other.end(), this->begin()); // may throw
+ }
+
+ //! @pre <tt>other.size() <= capacity()</tt>.
+ //!
+ //! @brief Constructs a copy of other varray.
+ //!
+ //! @param other The varray which content will be copied to this one.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor throws.
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ template <std::size_t C, typename S>
+ varray(varray<value_type, C, S> const& other)
+ : m_size(other.size())
+ {
+ errh::check_capacity(*this, other.size()); // may throw
+
+ namespace sv = varray_detail;
+ sv::uninitialized_copy(other.begin(), other.end(), this->begin()); // may throw
+ }
+
+ //! @brief Copy assigns Values stored in the other varray to this one.
+ //!
+ //! @param other The varray which content will be copied to this one.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor or copy assignment throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ varray & operator=(BOOST_COPY_ASSIGN_REF(varray) other)
+ {
+ this->assign(other.begin(), other.end()); // may throw
+
+ return *this;
+ }
+
+ //! @pre <tt>other.size() <= capacity()</tt>
+ //!
+ //! @brief Copy assigns Values stored in the other varray to this one.
+ //!
+ //! @param other The varray which content will be copied to this one.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor or copy assignment throws.
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ template <std::size_t C, typename S>
+// TEMPORARY WORKAROUND
+#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
+ varray & operator=(::boost::rv< varray<value_type, C, S> > const& other)
+#else
+ varray & operator=(varray<value_type, C, S> const& other)
+#endif
+ {
+ this->assign(other.begin(), other.end()); // may throw
+
+ return *this;
+ }
+
+ //! @brief Move constructor. Moves Values stored in the other varray to this one.
+ //!
+ //! @param other The varray which content will be moved to this one.
+ //!
+ //! @par Throws
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor throws.
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor throws.
+ //! @internal
+ //! @li It throws only if \c use_memop_in_swap_and_move is \c false_type - default.
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ varray(BOOST_RV_REF(varray) other)
+ {
+ typedef typename
+ vt::use_memop_in_swap_and_move use_memop_in_swap_and_move;
+
+ this->move_ctor_dispatch(other, use_memop_in_swap_and_move());
+ }
+
+ //! @pre <tt>other.size() <= capacity()</tt>
+ //!
+ //! @brief Move constructor. Moves Values stored in the other varray to this one.
+ //!
+ //! @param other The varray which content will be moved to this one.
+ //!
+ //! @par Throws
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor throws.
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor throws.
+ //! @internal
+ //! @li It throws only if \c use_memop_in_swap_and_move is false_type - default.
+ //! @endinternal
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ template <std::size_t C, typename S>
+ varray(BOOST_RV_REF_3_TEMPL_ARGS(varray, value_type, C, S) other)
+ : m_size(other.m_size)
+ {
+ errh::check_capacity(*this, other.size()); // may throw
+
+ typedef typename
+ vt::use_memop_in_swap_and_move use_memop_in_swap_and_move;
+
+ this->move_ctor_dispatch(other, use_memop_in_swap_and_move());
+ }
+
+ //! @brief Move assignment. Moves Values stored in the other varray to this one.
+ //!
+ //! @param other The varray which content will be moved to this one.
+ //!
+ //! @par Throws
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws.
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws.
+ //! @internal
+ //! @li It throws only if \c use_memop_in_swap_and_move is \c false_type - default.
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ varray & operator=(BOOST_RV_REF(varray) other)
+ {
+ if ( &other == this )
+ return *this;
+
+ typedef typename
+ vt::use_memop_in_swap_and_move use_memop_in_swap_and_move;
+
+ this->move_assign_dispatch(other, use_memop_in_swap_and_move());
+
+ return *this;
+ }
+
+ //! @pre <tt>other.size() <= capacity()</tt>
+ //!
+ //! @brief Move assignment. Moves Values stored in the other varray to this one.
+ //!
+ //! @param other The varray which content will be moved to this one.
+ //!
+ //! @par Throws
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws.
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws.
+ //! @internal
+ //! @li It throws only if \c use_memop_in_swap_and_move is \c false_type - default.
+ //! @endinternal
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ template <std::size_t C, typename S>
+ varray & operator=(BOOST_RV_REF_3_TEMPL_ARGS(varray, value_type, C, S) other)
+ {
+ errh::check_capacity(*this, other.size()); // may throw
+
+ typedef typename
+ vt::use_memop_in_swap_and_move use_memop_in_swap_and_move;
+
+ this->move_assign_dispatch(other, use_memop_in_swap_and_move());
+
+ return *this;
+ }
+
+ //! @brief Destructor. Destroys Values stored in this container.
+ //!
+ //! @par Throws
+ //! Nothing
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ ~varray()
+ {
+ namespace sv = varray_detail;
+ sv::destroy(this->begin(), this->end());
+ }
+
+ //! @brief Swaps contents of the other varray and this one.
+ //!
+ //! @param other The varray which content will be swapped with this one's content.
+ //!
+ //! @par Throws
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws,
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws,
+ //! @internal
+ //! @li It throws only if \c use_memop_in_swap_and_move and \c use_optimized_swap are \c false_type - default.
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ void swap(varray & other)
+ {
+ typedef typename
+ vt::use_optimized_swap use_optimized_swap;
+
+ this->swap_dispatch(other, use_optimized_swap());
+ }
+
+ //! @pre <tt>other.size() <= capacity() && size() <= other.capacity()</tt>
+ //!
+ //! @brief Swaps contents of the other varray and this one.
+ //!
+ //! @param other The varray which content will be swapped with this one's content.
+ //!
+ //! @par Throws
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws,
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws,
+ //! @internal
+ //! @li It throws only if \c use_memop_in_swap_and_move and \c use_optimized_swap are \c false_type - default.
+ //! @endinternal
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ template <std::size_t C, typename S>
+ void swap(varray<value_type, C, S> & other)
+ {
+ errh::check_capacity(*this, other.size());
+ errh::check_capacity(other, this->size());
+
+ typedef typename
+ vt::use_optimized_swap use_optimized_swap;
+
+ this->swap_dispatch(other, use_optimized_swap());
+ }
+
+ //! @pre <tt>count <= capacity()</tt>
+ //!
+ //! @brief Inserts or erases elements at the end such that
+ //! the size becomes count. New elements are value initialized.
+ //!
+ //! @param count The number of elements which will be stored in the container.
+ //!
+ //! @par Throws
+ //! If Value's value initialization throws.
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ void resize(size_type count)
+ {
+ namespace sv = varray_detail;
+ typedef typename vt::disable_trivial_init dti;
+
+ if ( count < m_size )
+ {
+ sv::destroy(this->begin() + count, this->end());
+ }
+ else
+ {
+ errh::check_capacity(*this, count); // may throw
+
+ sv::uninitialized_fill(this->end(), this->begin() + count, dti()); // may throw
+ }
+ m_size = count; // update end
+ }
+
+ //! @pre <tt>count <= capacity()</tt>
+ //!
+ //! @brief Inserts or erases elements at the end such that
+ //! the size becomes count. New elements are copy constructed from value.
+ //!
+ //! @param count The number of elements which will be stored in the container.
+ //! @param value The value used to copy construct the new element.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor throws.
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ void resize(size_type count, value_type const& value)
+ {
+ if ( count < m_size )
+ {
+ namespace sv = varray_detail;
+ sv::destroy(this->begin() + count, this->end());
+ }
+ else
+ {
+ errh::check_capacity(*this, count); // may throw
+
+ std::uninitialized_fill(this->end(), this->begin() + count, value); // may throw
+ }
+ m_size = count; // update end
+ }
+
+ //! @pre <tt>count <= capacity()</tt>
+ //!
+ //! @brief This call has no effect because the Capacity of this container is constant.
+ //!
+ //! @param count The number of elements which the container should be able to contain.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ void reserve(size_type count)
+ {
+ errh::check_capacity(*this, count); // may throw
+ }
+
+ //! @pre <tt>size() < capacity()</tt>
+ //!
+ //! @brief Adds a copy of value at the end.
+ //!
+ //! @param value The value used to copy construct the new element.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor throws.
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ void push_back(value_type const& value)
+ {
+ typedef typename vt::disable_trivial_init dti;
+
+ errh::check_capacity(*this, m_size + 1); // may throw
+
+ namespace sv = varray_detail;
+ sv::construct(dti(), this->end(), value); // may throw
+ ++m_size; // update end
+ }
+
+ //! @pre <tt>size() < capacity()</tt>
+ //!
+ //! @brief Moves value to the end.
+ //!
+ //! @param value The value to move construct the new element.
+ //!
+ //! @par Throws
+ //! If Value's move constructor throws.
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ void push_back(BOOST_RV_REF(value_type) value)
+ {
+ typedef typename vt::disable_trivial_init dti;
+
+ errh::check_capacity(*this, m_size + 1); // may throw
+
+ namespace sv = varray_detail;
+ sv::construct(dti(), this->end(), ::boost::move(value)); // may throw
+ ++m_size; // update end
+ }
+
+ //! @pre <tt>!empty()</tt>
+ //!
+ //! @brief Destroys last value and decreases the size.
+ //!
+ //! @par Throws
+ //! Nothing by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ void pop_back()
+ {
+ errh::check_empty(*this);
+
+ namespace sv = varray_detail;
+ sv::destroy(this->end() - 1);
+ --m_size; // update end
+ }
+
+ //! @pre
+ //! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
+ //! @li <tt>size() < capacity()</tt>
+ //!
+ //! @brief Inserts a copy of element at position.
+ //!
+ //! @param position The position at which the new value will be inserted.
+ //! @param value The value used to copy construct the new element.
+ //!
+ //! @par Throws
+ //! @li If Value's copy constructor or copy assignment throws
+ //! @li If Value's move constructor or move assignment throws.
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Constant or linear.
+ iterator insert(iterator position, value_type const& value)
+ {
+ return this->priv_insert(position, value);
+ }
+
+ //! @pre
+ //! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
+ //! @li <tt>size() < capacity()</tt>
+ //!
+ //! @brief Inserts a move-constructed element at position.
+ //!
+ //! @param position The position at which the new value will be inserted.
+ //! @param value The value used to move construct the new element.
+ //!
+ //! @par Throws
+ //! If Value's move constructor or move assignment throws.
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Constant or linear.
+ iterator insert(iterator position, BOOST_RV_REF(value_type) value)
+ {
+ return this->priv_insert(position, boost::move(value));
+ }
+
+ //! @pre
+ //! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
+ //! @li <tt>size() + count <= capacity()</tt>
+ //!
+ //! @brief Inserts a count copies of value at position.
+ //!
+ //! @param position The position at which new elements will be inserted.
+ //! @param count The number of new elements which will be inserted.
+ //! @param value The value used to copy construct new elements.
+ //!
+ //! @par Throws
+ //! @li If Value's copy constructor or copy assignment throws.
+ //! @li If Value's move constructor or move assignment throws.
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ iterator insert(iterator position, size_type count, value_type const& value)
+ {
+ errh::check_iterator_end_eq(*this, position);
+ errh::check_capacity(*this, m_size + count); // may throw
+
+ if ( position == this->end() )
+ {
+ std::uninitialized_fill(position, position + count, value); // may throw
+ m_size += count; // update end
+ }
+ else
+ {
+ namespace sv = varray_detail;
+
+ difference_type to_move = boost::container::iterator_distance(position, this->end());
+
+ // TODO - should following lines check for exception and revert to the old size?
+
+ if ( count < static_cast<size_type>(to_move) )
+ {
+ sv::uninitialized_move(this->end() - count, this->end(), this->end()); // may throw
+ m_size += count; // update end
+ sv::move_backward(position, position + to_move - count, this->end() - count); // may throw
+ std::fill_n(position, count, value); // may throw
+ }
+ else
+ {
+ std::uninitialized_fill(this->end(), position + count, value); // may throw
+ m_size += count - to_move; // update end
+ sv::uninitialized_move(position, position + to_move, position + count); // may throw
+ m_size += to_move; // update end
+ std::fill_n(position, to_move, value); // may throw
+ }
+ }
+
+ return position;
+ }
+
+ //! @pre
+ //! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
+ //! @li <tt>distance(first, last) <= capacity()</tt>
+ //! @li \c Iterator must meet the \c ForwardIterator.
+ //!
+ //! @brief Inserts a copy of a range <tt>[first, last)</tt> at position.
+ //!
+ //! @param position The position at which new elements will be inserted.
+ //! @param first The iterator to the first element of a range used to construct new elements.
+ //! @param last The iterator to the one after the last element of a range used to construct new elements.
+ //!
+ //! @par Throws
+ //! @li If Value's constructor and assignment taking a dereferenced \c Iterator.
+ //! @li If Value's move constructor or move assignment throws.
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ template <typename Iterator>
+ iterator insert(iterator position, Iterator first, Iterator last)
+ {
+ this->insert_dispatch(position, first, last);
+ return position;
+ }
+
+ //! @pre \c position must be a valid iterator of \c *this in range <tt>[begin(), end())</tt>
+ //!
+ //! @brief Erases Value from position.
+ //!
+ //! @param position The position of the element which will be erased from the container.
+ //!
+ //! @par Throws
+ //! If Value's move assignment throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ iterator erase(iterator position)
+ {
+ namespace sv = varray_detail;
+
+ errh::check_iterator_end_neq(*this, position);
+
+ //TODO - add empty check?
+ //errh::check_empty(*this);
+
+ sv::move(position + 1, this->end(), position); // may throw
+ sv::destroy(this->end() - 1);
+ --m_size;
+
+ return position;
+ }
+
+ //! @pre
+ //! @li \c first and \c last must define a valid range
+ //! @li iterators must be in range <tt>[begin(), end()]</tt>
+ //!
+ //! @brief Erases Values from a range <tt>[first, last)</tt>.
+ //!
+ //! @param first The position of the first element of a range which will be erased from the container.
+ //! @param last The position of the one after the last element of a range which will be erased from the container.
+ //!
+ //! @par Throws
+ //! If Value's move assignment throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ iterator erase(iterator first, iterator last)
+ {
+ namespace sv = varray_detail;
+
+ errh::check_iterator_end_eq(*this, first);
+ errh::check_iterator_end_eq(*this, last);
+
+ difference_type n = boost::container::iterator_distance(first, last);
+
+ //TODO - add invalid range check?
+ //BOOST_ASSERT_MSG(0 <= n, "invalid range");
+ //TODO - add this->size() check?
+ //BOOST_ASSERT_MSG(n <= this->size(), "invalid range");
+
+ sv::move(last, this->end(), first); // may throw
+ sv::destroy(this->end() - n, this->end());
+ m_size -= n;
+
+ return first;
+ }
+
+ //! @pre <tt>distance(first, last) <= capacity()</tt>
+ //!
+ //! @brief Assigns a range <tt>[first, last)</tt> of Values to this container.
+ //!
+ //! @param first The iterator to the first element of a range used to construct new content of this container.
+ //! @param last The iterator to the one after the last element of a range used to construct new content of this container.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor or copy assignment throws,
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ template <typename Iterator>
+ void assign(Iterator first, Iterator last)
+ {
+ this->assign_dispatch(first, last); // may throw
+ }
+
+ //! @pre <tt>count <= capacity()</tt>
+ //!
+ //! @brief Assigns a count copies of value to this container.
+ //!
+ //! @param count The new number of elements which will be container in the container.
+ //! @param value The value which will be used to copy construct the new content.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor or copy assignment throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ void assign(size_type count, value_type const& value)
+ {
+ if ( count < m_size )
+ {
+ namespace sv = varray_detail;
+
+ std::fill_n(this->begin(), count, value); // may throw
+ sv::destroy(this->begin() + count, this->end());
+ }
+ else
+ {
+ errh::check_capacity(*this, count); // may throw
+
+ std::fill_n(this->begin(), m_size, value); // may throw
+ std::uninitialized_fill(this->end(), this->begin() + count, value); // may throw
+ }
+ m_size = count; // update end
+ }
+
+#if !defined(BOOST_CONTAINER_VARRAY_DISABLE_EMPLACE)
+#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
+ //! @pre <tt>size() < capacity()</tt>
+ //!
+ //! @brief Inserts a Value constructed with
+ //! \c std::forward<Args>(args)... in the end of the container.
+ //!
+ //! @param args The arguments of the constructor of the new element which will be created at the end of the container.
+ //!
+ //! @par Throws
+ //! If in-place constructor throws or Value's move constructor throws.
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ template<class ...Args>
+ void emplace_back(BOOST_FWD_REF(Args) ...args)
+ {
+ typedef typename vt::disable_trivial_init dti;
+
+ errh::check_capacity(*this, m_size + 1); // may throw
+
+ namespace sv = varray_detail;
+ sv::construct(dti(), this->end(), ::boost::forward<Args>(args)...); // may throw
+ ++m_size; // update end
+ }
+
+ //! @pre
+ //! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>
+ //! @li <tt>size() < capacity()</tt>
+ //!
+ //! @brief Inserts a Value constructed with
+ //! \c std::forward<Args>(args)... before position
+ //!
+ //! @param position The position at which new elements will be inserted.
+ //! @param args The arguments of the constructor of the new element.
+ //!
+ //! @par Throws
+ //! If in-place constructor throws or if Value's move constructor or move assignment throws.
+ //! @internal
+ //! @li If a throwing error handler is specified, throws when the capacity is exceeded. (not by default).
+ //! @endinternal
+ //!
+ //! @par Complexity
+ //! Constant or linear.
+ template<class ...Args>
+ iterator emplace(iterator position, BOOST_FWD_REF(Args) ...args)
+ {
+ typedef typename vt::disable_trivial_init dti;
+
+ namespace sv = varray_detail;
+
+ errh::check_iterator_end_eq(*this, position);
+ errh::check_capacity(*this, m_size + 1); // may throw
+
+ if ( position == this->end() )
+ {
+ sv::construct(dti(), position, ::boost::forward<Args>(args)...); // may throw
+ ++m_size; // update end
+ }
+ else
+ {
+ // TODO - should following lines check for exception and revert to the old size?
+
+ // TODO - should move be used only if it's nonthrowing?
+ value_type & r = *(this->end() - 1);
+ sv::construct(dti(), this->end(), boost::move(r)); // may throw
+ ++m_size; // update end
+ sv::move_backward(position, this->end() - 2, this->end() - 1); // may throw
+
+ typename aligned_storage
+ <sizeof(value_type), alignment_of<value_type>::value>::type temp_storage;
+ value_type * val_p = static_cast<value_type*>(static_cast<void*>(&temp_storage));
+ sv::construct(dti(), val_p, ::boost::forward<Args>(args)...); // may throw
+ sv::scoped_destructor<value_type> d(val_p);
+ sv::assign(position, ::boost::move(*val_p)); // may throw
+ }
+
+ return position;
+ }
+
+#else // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || BOOST_CONTAINER_DOXYGEN_INVOKED
+
+ #define BOOST_CONTAINER_VARRAY_EMPLACE_CODE(N) \
+ BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
+ void emplace_back(BOOST_MOVE_UREF##N)\
+ {\
+ typedef typename vt::disable_trivial_init dti;\
+ errh::check_capacity(*this, m_size + 1);/*may throw*/\
+ \
+ namespace sv = varray_detail;\
+ sv::construct(dti(), this->end() BOOST_MOVE_I##N BOOST_MOVE_FWD##N ); /*may throw*/\
+ ++m_size; /*update end*/\
+ }\
+ \
+ BOOST_MOVE_TMPL_LT##N BOOST_MOVE_CLASS##N BOOST_MOVE_GT##N \
+ iterator emplace(iterator position BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
+ {\
+ typedef typename vt::disable_trivial_init dti;\
+ namespace sv = varray_detail;\
+ errh::check_iterator_end_eq(*this, position);\
+ errh::check_capacity(*this, m_size + 1); /*may throw*/\
+ if ( position == this->end() ){\
+ sv::construct(dti(), position BOOST_MOVE_I##N BOOST_MOVE_FWD##N ); /*may throw*/\
+ ++m_size; /*update end*/\
+ }\
+ else{\
+ /* TODO - should following lines check for exception and revert to the old size? */\
+ /* TODO - should move be used only if it's nonthrowing? */\
+ value_type & r = *(this->end() - 1);\
+ sv::construct(dti(), this->end(), boost::move(r));/*may throw*/\
+ ++m_size; /*update end*/\
+ sv::move_backward(position, this->end() - 2, this->end() - 1);/*may throw*/\
+ typename aligned_storage\
+ <sizeof(value_type), alignment_of<value_type>::value>::type temp_storage;\
+ value_type * val_p = static_cast<value_type*>(static_cast<void*>(&temp_storage));\
+ sv::construct(dti(), val_p BOOST_MOVE_I##N BOOST_MOVE_FWD##N ); /*may throw*/\
+ sv::scoped_destructor<value_type> d(val_p);\
+ sv::assign(position, ::boost::move(*val_p));/*may throw*/\
+ }\
+ return position;\
+ }\
+ BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_VARRAY_EMPLACE_CODE)
+ #undef BOOST_CONTAINER_VARRAY_EMPLACE_CODE
+
+#endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || BOOST_CONTAINER_DOXYGEN_INVOKED
+#endif // !BOOST_CONTAINER_VARRAY_DISABLE_EMPLACE
+
+ //! @brief Removes all elements from the container.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ void clear()
+ {
+ namespace sv = varray_detail;
+ sv::destroy(this->begin(), this->end());
+ m_size = 0; // update end
+ }
+
+ //! @pre <tt>i < size()</tt>
+ //!
+ //! @brief Returns reference to the i-th element.
+ //!
+ //! @param i The element's index.
+ //!
+ //! @return reference to the i-th element
+ //! from the beginning of the container.
+ //!
+ //! @par Throws
+ //! \c std::out_of_range exception by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ reference at(size_type i)
+ {
+ errh::check_at(*this, i); // may throw
+ return *(this->begin() + i);
+ }
+
+ //! @pre <tt>i < size()</tt>
+ //!
+ //! @brief Returns const reference to the i-th element.
+ //!
+ //! @param i The element's index.
+ //!
+ //! @return const reference to the i-th element
+ //! from the beginning of the container.
+ //!
+ //! @par Throws
+ //! \c std::out_of_range exception by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_reference at(size_type i) const
+ {
+ errh::check_at(*this, i); // may throw
+ return *(this->begin() + i);
+ }
+
+ //! @pre <tt>i < size()</tt>
+ //!
+ //! @brief Returns reference to the i-th element.
+ //!
+ //! @param i The element's index.
+ //!
+ //! @return reference to the i-th element
+ //! from the beginning of the container.
+ //!
+ //! @par Throws
+ //! Nothing by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ reference operator[](size_type i)
+ {
+ // TODO: Remove bounds check? std::vector and std::array operator[] don't check.
+ errh::check_operator_brackets(*this, i);
+ return *(this->begin() + i);
+ }
+
+ //! @pre <tt>i < size()</tt>
+ //!
+ //! @brief Returns const reference to the i-th element.
+ //!
+ //! @param i The element's index.
+ //!
+ //! @return const reference to the i-th element
+ //! from the beginning of the container.
+ //!
+ //! @par Throws
+ //! Nothing by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_reference operator[](size_type i) const
+ {
+ errh::check_operator_brackets(*this, i);
+ return *(this->begin() + i);
+ }
+
+ //! @pre \c !empty()
+ //!
+ //! @brief Returns reference to the first element.
+ //!
+ //! @return reference to the first element
+ //! from the beginning of the container.
+ //!
+ //! @par Throws
+ //! Nothing by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ reference front()
+ {
+ errh::check_empty(*this);
+ return *(this->begin());
+ }
+
+ //! @pre \c !empty()
+ //!
+ //! @brief Returns const reference to the first element.
+ //!
+ //! @return const reference to the first element
+ //! from the beginning of the container.
+ //!
+ //! @par Throws
+ //! Nothing by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_reference front() const
+ {
+ errh::check_empty(*this);
+ return *(this->begin());
+ }
+
+ //! @pre \c !empty()
+ //!
+ //! @brief Returns reference to the last element.
+ //!
+ //! @return reference to the last element
+ //! from the beginning of the container.
+ //!
+ //! @par Throws
+ //! Nothing by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ reference back()
+ {
+ errh::check_empty(*this);
+ return *(this->end() - 1);
+ }
+
+ //! @pre \c !empty()
+ //!
+ //! @brief Returns const reference to the first element.
+ //!
+ //! @return const reference to the last element
+ //! from the beginning of the container.
+ //!
+ //! @par Throws
+ //! Nothing by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_reference back() const
+ {
+ errh::check_empty(*this);
+ return *(this->end() - 1);
+ }
+
+ //! @brief Pointer such that <tt>[data(), data() + size())</tt> is a valid range.
+ //! For a non-empty vector <tt>data() == &front()</tt>.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ Value * data()
+ {
+ return (addressof)(*(this->ptr()));
+ }
+
+ //! @brief Const pointer such that <tt>[data(), data() + size())</tt> is a valid range.
+ //! For a non-empty vector <tt>data() == &front()</tt>.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const Value * data() const
+ {
+ return (addressof)(*(this->ptr()));
+ }
+
+
+ //! @brief Returns iterator to the first element.
+ //!
+ //! @return iterator to the first element contained in the vector.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ iterator begin() { return this->ptr(); }
+
+ //! @brief Returns const iterator to the first element.
+ //!
+ //! @return const_iterator to the first element contained in the vector.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_iterator begin() const { return this->ptr(); }
+
+ //! @brief Returns const iterator to the first element.
+ //!
+ //! @return const_iterator to the first element contained in the vector.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_iterator cbegin() const { return this->ptr(); }
+
+ //! @brief Returns iterator to the one after the last element.
+ //!
+ //! @return iterator pointing to the one after the last element contained in the vector.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ iterator end() { return this->begin() + m_size; }
+
+ //! @brief Returns const iterator to the one after the last element.
+ //!
+ //! @return const_iterator pointing to the one after the last element contained in the vector.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_iterator end() const { return this->begin() + m_size; }
+
+ //! @brief Returns const iterator to the one after the last element.
+ //!
+ //! @return const_iterator pointing to the one after the last element contained in the vector.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_iterator cend() const { return this->cbegin() + m_size; }
+
+ //! @brief Returns reverse iterator to the first element of the reversed container.
+ //!
+ //! @return reverse_iterator pointing to the beginning
+ //! of the reversed varray.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ reverse_iterator rbegin() { return reverse_iterator(this->end()); }
+
+ //! @brief Returns const reverse iterator to the first element of the reversed container.
+ //!
+ //! @return const_reverse_iterator pointing to the beginning
+ //! of the reversed varray.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_reverse_iterator rbegin() const { return reverse_iterator(this->end()); }
+
+ //! @brief Returns const reverse iterator to the first element of the reversed container.
+ //!
+ //! @return const_reverse_iterator pointing to the beginning
+ //! of the reversed varray.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_reverse_iterator crbegin() const { return reverse_iterator(this->end()); }
+
+ //! @brief Returns reverse iterator to the one after the last element of the reversed container.
+ //!
+ //! @return reverse_iterator pointing to the one after the last element
+ //! of the reversed varray.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ reverse_iterator rend() { return reverse_iterator(this->begin()); }
+
+ //! @brief Returns const reverse iterator to the one after the last element of the reversed container.
+ //!
+ //! @return const_reverse_iterator pointing to the one after the last element
+ //! of the reversed varray.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_reverse_iterator rend() const { return reverse_iterator(this->begin()); }
+
+ //! @brief Returns const reverse iterator to the one after the last element of the reversed container.
+ //!
+ //! @return const_reverse_iterator pointing to the one after the last element
+ //! of the reversed varray.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_reverse_iterator crend() const { return reverse_iterator(this->begin()); }
+
+ //! @brief Returns container's capacity.
+ //!
+ //! @return container's capacity.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ static size_type capacity() { return Capacity; }
+
+ //! @brief Returns container's capacity.
+ //!
+ //! @return container's capacity.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ static size_type max_size() { return Capacity; }
+
+ //! @brief Returns the number of stored elements.
+ //!
+ //! @return Number of elements contained in the container.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ size_type size() const { return m_size; }
+
+ //! @brief Queries if the container contains elements.
+ //!
+ //! @return true if the number of elements contained in the
+ //! container is equal to 0.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ bool empty() const { return 0 == m_size; }
+
+private:
+
+ // @par Throws
+ // Nothing.
+ // @par Complexity
+ // Linear O(N).
+ template <std::size_t C, typename S>
+ void move_ctor_dispatch(varray<value_type, C, S> & other, true_type /*use_memop*/)
+ {
+ ::memcpy(this->data(), other.data(), sizeof(Value) * other.m_size);
+ m_size = other.m_size;
+ }
+
+ // @par Throws
+ // @li If boost::has_nothrow_move<Value>::value is true and Value's move constructor throws
+ // @li If boost::has_nothrow_move<Value>::value is false and Value's copy constructor throws.
+ // @par Complexity
+ // Linear O(N).
+ template <std::size_t C, typename S>
+ void move_ctor_dispatch(varray<value_type, C, S> & other, false_type /*use_memop*/)
+ {
+ namespace sv = varray_detail;
+ sv::uninitialized_move_if_noexcept(other.begin(), other.end(), this->begin()); // may throw
+ m_size = other.m_size;
+ }
+
+ // @par Throws
+ // Nothing.
+ // @par Complexity
+ // Linear O(N).
+ template <std::size_t C, typename S>
+ void move_assign_dispatch(varray<value_type, C, S> & other, true_type /*use_memop*/)
+ {
+ this->clear();
+
+ ::memcpy(this->data(), other.data(), sizeof(Value) * other.m_size);
+ boost::adl_move_swap(m_size, other.m_size);
+ }
+
+ // @par Throws
+ // @li If boost::has_nothrow_move<Value>::value is true and Value's move constructor or move assignment throws
+ // @li If boost::has_nothrow_move<Value>::value is false and Value's copy constructor or move assignment throws.
+ // @par Complexity
+ // Linear O(N).
+ template <std::size_t C, typename S>
+ void move_assign_dispatch(varray<value_type, C, S> & other, false_type /*use_memop*/)
+ {
+ namespace sv = varray_detail;
+ if ( m_size <= static_cast<size_type>(other.size()) )
+ {
+ sv::move_if_noexcept(other.begin(), other.begin() + m_size, this->begin()); // may throw
+ // TODO - perform uninitialized_copy first?
+ sv::uninitialized_move_if_noexcept(other.begin() + m_size, other.end(), this->end()); // may throw
+ }
+ else
+ {
+ sv::move_if_noexcept(other.begin(), other.end(), this->begin()); // may throw
+ sv::destroy(this->begin() + other.size(), this->end());
+ }
+ m_size = other.size(); // update end
+ }
+
+ // @par Throws
+ // Nothing.
+ // @par Complexity
+ // Linear O(N).
+ template <std::size_t C, typename S>
+ void swap_dispatch(varray<value_type, C, S> & other, true_type const& /*use_optimized_swap*/)
+ {
+ typedef typename
+ if_c<
+ Capacity < C,
+ aligned_storage_type,
+ typename varray<value_type, C, S>::aligned_storage_type
+ >::type
+ storage_type;
+
+ storage_type temp_storage;
+ value_type * temp_ptr = static_cast<value_type*>(static_cast<void*>(&temp_storage));
+
+ ::memcpy(temp_ptr, this->data(), sizeof(Value) * this->size());
+ ::memcpy(this->data(), other.data(), sizeof(Value) * other.size());
+ ::memcpy(other.data(), temp_ptr, sizeof(Value) * this->size());
+
+ boost::adl_move_swap(m_size, other.m_size);
+ }
+
+ // @par Throws
+ // If Value's move constructor or move assignment throws
+ // but only if use_memop_in_swap_and_move is false_type - default.
+ // @par Complexity
+ // Linear O(N).
+ template <std::size_t C, typename S>
+ void swap_dispatch(varray<value_type, C, S> & other, false_type const& /*use_optimized_swap*/)
+ {
+ namespace sv = varray_detail;
+
+ typedef typename
+ vt::use_memop_in_swap_and_move use_memop_in_swap_and_move;
+
+ if ( this->size() < other.size() )
+ swap_dispatch_impl(this->begin(), this->end(), other.begin(), other.end(), use_memop_in_swap_and_move()); // may throw
+ else
+ swap_dispatch_impl(other.begin(), other.end(), this->begin(), this->end(), use_memop_in_swap_and_move()); // may throw
+ boost::adl_move_swap(m_size, other.m_size);
+ }
+
+ // @par Throws
+ // Nothing.
+ // @par Complexity
+ // Linear O(N).
+ void swap_dispatch_impl(iterator first_sm, iterator last_sm, iterator first_la, iterator last_la, true_type const& /*use_memop*/)
+ {
+ //BOOST_ASSERT_MSG(boost::container::iterator_distance(first_sm, last_sm) <= boost::container::iterator_distance(first_la, last_la));
+
+ namespace sv = varray_detail;
+ for (; first_sm != last_sm ; ++first_sm, ++first_la)
+ {
+ typename aligned_storage<
+ sizeof(value_type),
+ alignment_of<value_type>::value
+ >::type temp_storage;
+ value_type * temp_ptr = static_cast<value_type*>(static_cast<void*>(&temp_storage));
+ ::memcpy(temp_ptr, (addressof)(*first_sm), sizeof(value_type));
+ ::memcpy((addressof)(*first_sm), (addressof)(*first_la), sizeof(value_type));
+ ::memcpy((addressof)(*first_la), temp_ptr, sizeof(value_type));
+ }
+
+ ::memcpy(first_sm, first_la, sizeof(value_type) * boost::container::iterator_distance(first_la, last_la));
+ }
+
+ // @par Throws
+ // If Value's move constructor or move assignment throws.
+ // @par Complexity
+ // Linear O(N).
+ void swap_dispatch_impl(iterator first_sm, iterator last_sm, iterator first_la, iterator last_la, false_type const& /*use_memop*/)
+ {
+ //BOOST_ASSERT_MSG(boost::container::iterator_distance(first_sm, last_sm) <= boost::container::iterator_distance(first_la, last_la));
+
+ namespace sv = varray_detail;
+ for (; first_sm != last_sm ; ++first_sm, ++first_la)
+ {
+ //boost::adl_move_swap(*first_sm, *first_la); // may throw
+ value_type temp(boost::move(*first_sm)); // may throw
+ *first_sm = boost::move(*first_la); // may throw
+ *first_la = boost::move(temp); // may throw
+ }
+ sv::uninitialized_move(first_la, last_la, first_sm); // may throw
+ sv::destroy(first_la, last_la);
+ }
+
+ // insert
+
+ // @par Throws
+ // If Value's move constructor or move assignment throws
+ // or if Value's copy assignment throws.
+ // @par Complexity
+ // Linear O(N).
+ template <typename V>
+ iterator priv_insert(iterator position, V & value)
+ {
+ typedef typename vt::disable_trivial_init dti;
+ namespace sv = varray_detail;
+
+ errh::check_iterator_end_eq(*this, position);
+ errh::check_capacity(*this, m_size + 1); // may throw
+
+ if ( position == this->end() )
+ {
+ sv::construct(dti(), position, value); // may throw
+ ++m_size; // update end
+ }
+ else
+ {
+ // TODO - should following lines check for exception and revert to the old size?
+
+ // TODO - should move be used only if it's nonthrowing?
+ value_type & r = *(this->end() - 1);
+ sv::construct(dti(), this->end(), boost::move(r)); // may throw
+ ++m_size; // update end
+ sv::move_backward(position, this->end() - 2, this->end() - 1); // may throw
+ sv::assign(position, value); // may throw
+ }
+
+ return position;
+ }
+
+ // insert
+
+ // @par Throws
+ // If Value's move constructor, move assignment throws
+ // or if Value's copy constructor or copy assignment throws.
+ // @par Complexity
+ // Linear O(N).
+ template <typename Iterator>
+ typename iterator_enable_if_tag<Iterator, std::random_access_iterator_tag>::type
+ insert_dispatch(iterator position, Iterator first, Iterator last)
+ {
+ errh::check_iterator_end_eq(*this, position);
+
+ size_type count = boost::container::iterator_distance(first, last);
+
+ errh::check_capacity(*this, m_size + count); // may throw
+
+ if ( position == this->end() )
+ {
+ namespace sv = varray_detail;
+
+ sv::uninitialized_copy(first, last, position); // may throw
+ m_size += count; // update end
+ }
+ else
+ {
+ this->insert_in_the_middle(position, first, last, count); // may throw
+ }
+ }
+
+ // @par Throws
+ // If Value's move constructor, move assignment throws
+ // or if Value's copy constructor or copy assignment throws.
+ // @par Complexity
+ // Linear O(N).
+ template <typename Iterator, typename Category>
+ typename iterator_disable_if_tag<Iterator, std::random_access_iterator_tag>::type
+ insert_dispatch(iterator position, Iterator first, Iterator last)
+ {
+ errh::check_iterator_end_eq(*this, position);
+
+ if ( position == this->end() )
+ {
+ namespace sv = varray_detail;
+
+ std::ptrdiff_t d = boost::container::iterator_distance(position, this->begin() + Capacity);
+ std::size_t count = sv::uninitialized_copy_s(first, last, position, d); // may throw
+
+ errh::check_capacity(*this, count <= static_cast<std::size_t>(d) ? m_size + count : Capacity + 1); // may throw
+
+ m_size += count;
+ }
+ else
+ {
+ size_type count = boost::container::iterator_distance(first, last);
+
+ errh::check_capacity(*this, m_size + count); // may throw
+
+ this->insert_in_the_middle(position, first, last, count); // may throw
+ }
+ }
+
+ // @par Throws
+ // If Value's move constructor, move assignment throws
+ // or if Value's copy constructor or copy assignment throws.
+ // @par Complexity
+ // Linear O(N).
+ template <typename Iterator>
+ void insert_in_the_middle(iterator position, Iterator first, Iterator last, difference_type count)
+ {
+ namespace sv = varray_detail;
+
+ difference_type to_move = boost::container::iterator_distance(position, this->end());
+
+ // TODO - should following lines check for exception and revert to the old size?
+
+ if ( count < to_move )
+ {
+ sv::uninitialized_move(this->end() - count, this->end(), this->end()); // may throw
+ m_size += count; // update end
+ sv::move_backward(position, position + to_move - count, this->end() - count); // may throw
+ sv::copy(first, last, position); // may throw
+ }
+ else
+ {
+ Iterator middle_iter = first;
+ boost::container::iterator_advance(middle_iter, to_move);
+
+ sv::uninitialized_copy(middle_iter, last, this->end()); // may throw
+ m_size += count - to_move; // update end
+ sv::uninitialized_move(position, position + to_move, position + count); // may throw
+ m_size += to_move; // update end
+ sv::copy(first, middle_iter, position); // may throw
+ }
+ }
+
+ // assign
+
+ // @par Throws
+ // If Value's constructor or assignment taking dereferenced Iterator throws.
+ // @par Complexity
+ // Linear O(N).
+ template <typename Iterator>
+ typename iterator_enable_if_tag<Iterator, std::random_access_iterator_tag>::type
+ assign_dispatch(Iterator first, Iterator last)
+ {
+ namespace sv = varray_detail;
+
+ size_type s = boost::container::iterator_distance(first, last);
+
+ errh::check_capacity(*this, s); // may throw
+
+ if ( m_size <= static_cast<size_type>(s) )
+ {
+ sv::copy(first, first + m_size, this->begin()); // may throw
+ // TODO - perform uninitialized_copy first?
+ sv::uninitialized_copy(first + m_size, last, this->end()); // may throw
+ }
+ else
+ {
+ sv::copy(first, last, this->begin()); // may throw
+ sv::destroy(this->begin() + s, this->end());
+ }
+ m_size = s; // update end
+ }
+
+ // @par Throws
+ // If Value's constructor or assignment taking dereferenced Iterator throws.
+ // @par Complexity
+ // Linear O(N).
+ template <typename Iterator, typename Category>
+ typename iterator_disable_if_tag<Iterator, std::random_access_iterator_tag>::type
+ assign_dispatch(Iterator first, Iterator last)
+ {
+ namespace sv = varray_detail;
+
+ size_type s = 0;
+ iterator it = this->begin();
+
+ for ( ; it != this->end() && first != last ; ++it, ++first, ++s )
+ *it = *first; // may throw
+
+ sv::destroy(it, this->end());
+
+ std::ptrdiff_t d = boost::container::iterator_distance(it, this->begin() + Capacity);
+ std::size_t count = sv::uninitialized_copy_s(first, last, it, d); // may throw
+ s += count;
+
+ errh::check_capacity(*this, count <= static_cast<std::size_t>(d) ? s : Capacity + 1); // may throw
+
+ m_size = s; // update end
+ }
+
+ pointer ptr()
+ {
+ return pointer(static_cast<Value*>(static_cast<void*>(&m_storage)));
+ }
+
+ const_pointer ptr() const
+ {
+ return pointer(static_cast<const Value*>(static_cast<const void*>(&m_storage)));
+ }
+
+ size_type m_size;
+ aligned_storage_type m_storage;
+};
+
+#if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
+
+template<typename Value, typename Strategy>
+class varray<Value, 0, Strategy>
+{
+ typedef varray_traits<
+ Value, 0, Strategy
+ > vt;
+
+ typedef typename vt::size_type stored_size_type;
+ typedef typename vt::error_handler errh;
+
+public:
+ typedef typename vt::value_type value_type;
+ typedef stored_size_type size_type;
+ typedef typename vt::difference_type difference_type;
+ typedef typename vt::pointer pointer;
+ typedef typename vt::const_pointer const_pointer;
+ typedef typename vt::reference reference;
+ typedef typename vt::const_reference const_reference;
+
+ typedef pointer iterator;
+ typedef const_pointer const_iterator;
+ typedef boost::container::reverse_iterator<iterator> reverse_iterator;
+ typedef boost::container::reverse_iterator<const_iterator> const_reverse_iterator;
+
+ // nothrow
+ varray() {}
+
+ // strong
+ explicit varray(size_type count)
+ {
+ errh::check_capacity(*this, count); // may throw
+ }
+
+ // strong
+ varray(size_type count, value_type const&)
+ {
+ errh::check_capacity(*this, count); // may throw
+ }
+
+ // strong
+ varray(varray const& other)
+ {
+ //errh::check_capacity(*this, count);
+ }
+
+ // strong
+ template <size_t C, typename S>
+ varray(varray<value_type, C, S> const& other)
+ {
+ errh::check_capacity(*this, other.size()); // may throw
+ }
+
+ // strong
+ template <typename Iterator>
+ varray(Iterator first, Iterator last)
+ {
+ errh::check_capacity(*this, boost::container::iterator_distance(first, last)); // may throw
+ }
+
+ // basic
+ varray & operator=(varray const& other)
+ {
+ //errh::check_capacity(*this, other.size());
+ return *this;
+ }
+
+ // basic
+ template <size_t C, typename S>
+ varray & operator=(varray<value_type, C, S> const& other)
+ {
+ errh::check_capacity(*this, other.size()); // may throw
+ return *this;
+ }
+
+ // nothrow
+ ~varray() {}
+
+ // strong
+ void resize(size_type count)
+ {
+ errh::check_capacity(*this, count); // may throw
+ }
+
+ // strong
+ void resize(size_type count, value_type const&)
+ {
+ errh::check_capacity(*this, count); // may throw
+ }
+
+
+ // nothrow
+ void reserve(size_type count)
+ {
+ errh::check_capacity(*this, count); // may throw
+ }
+
+ // strong
+ void push_back(value_type const&)
+ {
+ errh::check_capacity(*this, 1); // may throw
+ }
+
+ // nothrow
+ void pop_back()
+ {
+ errh::check_empty(*this);
+ }
+
+ // basic
+ void insert(iterator position, value_type const&)
+ {
+ errh::check_iterator_end_eq(*this, position);
+ errh::check_capacity(*this, 1); // may throw
+ }
+
+ // basic
+ void insert(iterator position, size_type count, value_type const&)
+ {
+ errh::check_iterator_end_eq(*this, position);
+ errh::check_capacity(*this, count); // may throw
+ }
+
+ // basic
+ template <typename Iterator>
+ void insert(iterator, Iterator first, Iterator last)
+ {
+ errh::check_capacity(*this, boost::container::iterator_distance(first, last)); // may throw
+ }
+
+ // basic
+ void erase(iterator position)
+ {
+ errh::check_iterator_end_neq(*this, position);
+ }
+
+ // basic
+ void erase(iterator first, iterator last)
+ {
+ errh::check_iterator_end_eq(*this, first);
+ errh::check_iterator_end_eq(*this, last);
+
+ //BOOST_ASSERT_MSG(0 <= n, "invalid range");
+ }
+
+ // basic
+ template <typename Iterator>
+ void assign(Iterator first, Iterator last)
+ {
+ errh::check_capacity(*this, boost::container::iterator_distance(first, last)); // may throw
+ }
+
+ // basic
+ void assign(size_type count, value_type const&)
+ {
+ errh::check_capacity(*this, count); // may throw
+ }
+
+ // nothrow
+ void clear() {}
+
+ // strong
+ reference at(size_type i)
+ {
+ errh::check_at(*this, i); // may throw
+ return *(this->begin() + i);
+ }
+
+ // strong
+ const_reference at(size_type i) const
+ {
+ errh::check_at(*this, i); // may throw
+ return *(this->begin() + i);
+ }
+
+ // nothrow
+ reference operator[](size_type i)
+ {
+ errh::check_operator_brackets(*this, i);
+ return *(this->begin() + i);
+ }
+
+ // nothrow
+ const_reference operator[](size_type i) const
+ {
+ errh::check_operator_brackets(*this, i);
+ return *(this->begin() + i);
+ }
+
+ // nothrow
+ reference front()
+ {
+ errh::check_empty(*this);
+ return *(this->begin());
+ }
+
+ // nothrow
+ const_reference front() const
+ {
+ errh::check_empty(*this);
+ return *(this->begin());
+ }
+
+ // nothrow
+ reference back()
+ {
+ errh::check_empty(*this);
+ return *(this->end() - 1);
+ }
+
+ // nothrow
+ const_reference back() const
+ {
+ errh::check_empty(*this);
+ return *(this->end() - 1);
+ }
+
+ // nothrow
+ Value * data() { return (addressof)(*(this->ptr())); }
+ const Value * data() const { return (addressof)(*(this->ptr())); }
+
+ // nothrow
+ iterator begin() { return this->ptr(); }
+ const_iterator begin() const { return this->ptr(); }
+ const_iterator cbegin() const { return this->ptr(); }
+ iterator end() { return this->begin(); }
+ const_iterator end() const { return this->begin(); }
+ const_iterator cend() const { return this->cbegin(); }
+ // nothrow
+ reverse_iterator rbegin() { return reverse_iterator(this->end()); }
+ const_reverse_iterator rbegin() const { return reverse_iterator(this->end()); }
+ const_reverse_iterator crbegin() const { return reverse_iterator(this->end()); }
+ reverse_iterator rend() { return reverse_iterator(this->begin()); }
+ const_reverse_iterator rend() const { return reverse_iterator(this->begin()); }
+ const_reverse_iterator crend() const { return reverse_iterator(this->begin()); }
+
+ // nothrow
+ size_type capacity() const { return 0; }
+ size_type max_size() const { return 0; }
+ size_type size() const { return 0; }
+ bool empty() const { return true; }
+
+private:
+
+ pointer ptr()
+ {
+ return pointer(reinterpret_cast<Value*>(this));
+ }
+
+ const_pointer ptr() const
+ {
+ return const_pointer(reinterpret_cast<const Value*>(this));
+ }
+};
+
+#endif // !BOOST_CONTAINER_DOXYGEN_INVOKED
+
+//! @brief Checks if contents of two varrays are equal.
+//!
+//! @ingroup varray_non_member
+//!
+//! @param x The first varray.
+//! @param y The second varray.
+//!
+//! @return \c true if containers have the same size and elements in both containers are equal.
+//!
+//! @par Complexity
+//! Linear O(N).
+template<typename V, std::size_t C1, typename S1, std::size_t C2, typename S2>
+bool operator== (varray<V, C1, S1> const& x, varray<V, C2, S2> const& y)
+{
+ return x.size() == y.size() && ::boost::container::algo_equal(x.begin(), x.end(), y.begin());
+}
+
+//! @brief Checks if contents of two varrays are not equal.
+//!
+//! @ingroup varray_non_member
+//!
+//! @param x The first varray.
+//! @param y The second varray.
+//!
+//! @return \c true if containers have different size or elements in both containers are not equal.
+//!
+//! @par Complexity
+//! Linear O(N).
+template<typename V, std::size_t C1, typename S1, std::size_t C2, typename S2>
+bool operator!= (varray<V, C1, S1> const& x, varray<V, C2, S2> const& y)
+{
+ return !(x==y);
+}
+
+//! @brief Lexicographically compares varrays.
+//!
+//! @ingroup varray_non_member
+//!
+//! @param x The first varray.
+//! @param y The second varray.
+//!
+//! @return \c true if x compares lexicographically less than y.
+//!
+//! @par Complexity
+//! Linear O(N).
+template<typename V, std::size_t C1, typename S1, std::size_t C2, typename S2>
+bool operator< (varray<V, C1, S1> const& x, varray<V, C2, S2> const& y)
+{
+ return ::boost::container::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());
+}
+
+//! @brief Lexicographically compares varrays.
+//!
+//! @ingroup varray_non_member
+//!
+//! @param x The first varray.
+//! @param y The second varray.
+//!
+//! @return \c true if y compares lexicographically less than x.
+//!
+//! @par Complexity
+//! Linear O(N).
+template<typename V, std::size_t C1, typename S1, std::size_t C2, typename S2>
+bool operator> (varray<V, C1, S1> const& x, varray<V, C2, S2> const& y)
+{
+ return y<x;
+}
+
+//! @brief Lexicographically compares varrays.
+//!
+//! @ingroup varray_non_member
+//!
+//! @param x The first varray.
+//! @param y The second varray.
+//!
+//! @return \c true if y don't compare lexicographically less than x.
+//!
+//! @par Complexity
+//! Linear O(N).
+template<typename V, std::size_t C1, typename S1, std::size_t C2, typename S2>
+bool operator<= (varray<V, C1, S1> const& x, varray<V, C2, S2> const& y)
+{
+ return !(y<x);
+}
+
+//! @brief Lexicographically compares varrays.
+//!
+//! @ingroup varray_non_member
+//!
+//! @param x The first varray.
+//! @param y The second varray.
+//!
+//! @return \c true if x don't compare lexicographically less than y.
+//!
+//! @par Complexity
+//! Linear O(N).
+template<typename V, std::size_t C1, typename S1, std::size_t C2, typename S2>
+bool operator>= (varray<V, C1, S1> const& x, varray<V, C2, S2> const& y)
+{
+ return !(x<y);
+}
+
+//! @brief Swaps contents of two varrays.
+//!
+//! This function calls varray::swap().
+//!
+//! @ingroup varray_non_member
+//!
+//! @param x The first varray.
+//! @param y The second varray.
+//!
+//! @par Complexity
+//! Linear O(N).
+template<typename V, std::size_t C1, typename S1, std::size_t C2, typename S2>
+inline void swap(varray<V, C1, S1> & x, varray<V, C2, S2> & y)
+{
+ x.swap(y);
+}
+
+}}} // namespace boost::container::dtl
+
+#include <boost/container/detail/config_end.hpp>
+
+#endif // BOOST_CONTAINER_DETAIL_VARRAY_HPP
diff --git a/bench/detail/varray_concept.hpp b/bench/detail/varray_concept.hpp
new file mode 100644
index 0000000..94d19bd
--- /dev/null
+++ b/bench/detail/varray_concept.hpp
@@ -0,0 +1,60 @@
+// Boost.Container varray
+//
+// Copyright (c) 2012-2013 Andrew Hundt.
+// Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
+//
+// Use, modification and distribution is subject to 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)
+
+#ifndef BOOST_CONTAINER_VARRAY_CONCEPT_HPP
+#define BOOST_CONTAINER_VARRAY_CONCEPT_HPP
+
+#include <boost/concept_check.hpp>
+
+namespace boost { namespace container { namespace dtl { namespace concept {
+
+/**
+ * VArrayStrategyConcept
+ *
+ * \brief Checks strategy for varray<Value,Capacity,Strategy>, which has similarities to std::allocator
+ * \ingroup varray
+ */
+template<typename Strategy>
+struct VArrayStrategy {
+#ifndef DOXYGEN_NO_CONCEPT_MEMBERS
+
+ // typedefs are the same as in std::allocator
+ typedef typename Strategy::value_type value_type;
+ typedef typename Strategy::size_type size_type;
+ typedef typename Strategy::difference_type difference_type;
+ typedef typename Strategy::pointer pointer;
+ typedef typename Strategy::const_pointer const_pointer;
+ typedef typename Strategy::reference reference;
+ typedef typename Strategy::const_reference const_reference;
+
+ struct check_methods
+ {
+ static void apply()
+ {
+ Strategy const* str = 0;
+
+ // must implement allocate_failed
+ str->allocate_failed();
+
+ boost::ignore_unused_variable_warning(str);
+ }
+ };
+
+public :
+ BOOST_CONCEPT_USAGE(VArrayStrategy)
+ {
+ check_methods::apply();
+ }
+
+#endif
+};
+
+}}}} // namespace boost::container::dtl::concept
+
+#endif //BOOST_CONTAINER_VARRAY_CONCEPT_HPP
diff --git a/bench/detail/varray_util.hpp b/bench/detail/varray_util.hpp
new file mode 100644
index 0000000..043e9e9
--- /dev/null
+++ b/bench/detail/varray_util.hpp
@@ -0,0 +1,646 @@
+// Boost.Container
+//
+// varray details
+//
+// Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
+// Copyright (c) 2011-2013 Andrew Hundt.
+//
+// Use, modification and distribution is subject to 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)
+
+#ifndef BOOST_CONTAINER_DETAIL_VARRAY_UTIL_HPP
+#define BOOST_CONTAINER_DETAIL_VARRAY_UTIL_HPP
+
+#include <cstddef>
+#include <cstring>
+#include <memory>
+#include <limits>
+
+#include <boost/config.hpp>
+#include <boost/core/no_exceptions_support.hpp>
+
+#include <boost/container/detail/addressof.hpp>
+#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
+#include <boost/move/detail/fwd_macros.hpp>
+#endif
+#include <boost/container/detail/iterator.hpp>
+#include <boost/container/detail/mpl.hpp>
+#include <boost/container/detail/type_traits.hpp>
+
+#include <boost/move/algorithm.hpp>
+#include <boost/move/traits.hpp>
+#include <boost/move/utility_core.hpp>
+
+// TODO - move vectors iterators optimization to the other, optional file instead of checking defines?
+
+#if defined(BOOST_CONTAINER_VARRAY_ENABLE_VECTORS_OPTIMIZATION) && !defined(BOOST_NO_EXCEPTIONS)
+#include <vector>
+#include <boost/container/vector.hpp>
+#endif // BOOST_CONTAINER_VARRAY_ENABLE_ITERATORS_OPTIMIZATION && !BOOST_NO_EXCEPTIONS
+
+namespace boost { namespace container { namespace varray_detail {
+
+namespace bcd = ::boost::container::dtl;
+
+template <typename I>
+struct are_elements_contiguous : boost::container::dtl::is_pointer<I>
+{};
+
+#if defined(BOOST_CONTAINER_VARRAY_ENABLE_VECTORS_OPTIMIZATION) && !defined(BOOST_NO_EXCEPTIONS)
+
+template <typename Pointer>
+struct are_elements_contiguous<
+ bcd::vector_const_iterator<Pointer>
+> : bcd::true_type
+{};
+
+template <typename Pointer>
+struct are_elements_contiguous<
+ bcd::vector_iterator<Pointer>
+> : bcd::true_type
+{};
+
+#if defined(BOOST_DINKUMWARE_STDLIB)
+
+template <typename T>
+struct are_elements_contiguous<
+ std::_Vector_const_iterator<T>
+> : bcd::true_type
+{};
+
+template <typename T>
+struct are_elements_contiguous<
+ std::_Vector_iterator<T>
+> : bcd::true_type
+{};
+
+#elif defined(BOOST_GNU_STDLIB)
+
+template <typename P, typename T, typename Allocator>
+struct are_elements_contiguous<
+ __gnu_cxx::__normal_iterator<P, std::vector<T, Allocator> >
+> : bcd::true_type
+{};
+
+#elif defined(_LIBCPP_VERSION)
+
+// TODO - test it first
+//template <typename P>
+//struct are_elements_contiguous<
+// __wrap_iter<P>
+//> : bcd::true_type
+//{};
+
+#else // OTHER_STDLIB
+
+// TODO - add other iterators implementations
+
+#endif // STDLIB
+
+#endif // BOOST_CONTAINER_VARRAY_ENABLE_VECTORS_OPTIMIZATION && !BOOST_NO_EXCEPTIONS
+
+template <typename I, typename O>
+struct are_corresponding :
+ bcd::bool_<
+ bcd::is_same<
+ bcd::remove_const<
+ typename ::boost::container::iterator_traits<I>::value_type
+ >,
+ bcd::remove_const<
+ typename ::boost::container::iterator_traits<O>::value_type
+ >
+ >::value &&
+ are_elements_contiguous<I>::value &&
+ are_elements_contiguous<O>::value
+ >
+{};
+
+template <typename I, typename V>
+struct is_corresponding_value :
+ bcd::bool_<
+ bcd::is_same<
+ bcd::remove_const<typename ::boost::container::iterator_traits<I>::value_type>,
+ bcd::remove_const<V>
+ >::value
+ >
+{};
+
+// destroy(I, I)
+
+template <typename I>
+void destroy_dispatch(I /*first*/, I /*last*/, bcd::true_type const& /*is_trivially_destructible*/)
+{}
+
+template <typename I>
+void destroy_dispatch(I first, I last, bcd::false_type const& /*is_trivially_destructible*/)
+{
+ typedef typename ::boost::container::iterator_traits<I>::value_type value_type;
+ for ( ; first != last ; ++first )
+ first->~value_type();
+}
+
+template <typename I>
+void destroy(I first, I last)
+{
+ typedef typename ::boost::container::iterator_traits<I>::value_type value_type;
+ destroy_dispatch(first, last, bcd::bool_<bcd::is_trivially_destructible<value_type>::value>());
+}
+
+// destroy(I)
+
+template <typename I>
+void destroy_dispatch(I /*pos*/,
+ bcd::true_type const& /*is_trivially_destructible*/)
+{}
+
+template <typename I>
+void destroy_dispatch(I pos,
+ bcd::false_type const& /*is_trivially_destructible*/)
+{
+ typedef typename ::boost::container::iterator_traits<I>::value_type value_type;
+ pos->~value_type();
+}
+
+template <typename I>
+void destroy(I pos)
+{
+ typedef typename ::boost::container::iterator_traits<I>::value_type value_type;
+ destroy_dispatch(pos, bcd::bool_<bcd::is_trivially_destructible<value_type>::value>());
+}
+
+// copy(I, I, O)
+
+template <typename I, typename O>
+inline O copy_dispatch(I first, I last, O dst, bcd::true_type const& /*use_memmove*/)
+{
+ typedef typename ::boost::container::iterator_traits<I>::value_type value_type;
+ const std::size_t d = boost::container::iterator_distance(first, last);
+ ::memmove(boost::container::dtl::addressof(*dst), boost::container::dtl::addressof(*first), sizeof(value_type) * d);
+ return dst + d;
+}
+
+template <typename I, typename O>
+inline O copy_dispatch(I first, I last, O dst, bcd::false_type const& /*use_memmove*/)
+{
+ return std::copy(first, last, dst); // may throw
+}
+
+template <typename I, typename O>
+inline O copy(I first, I last, O dst)
+{
+ typedef bcd::bool_
+ < are_corresponding<I, O>::value &&
+ bcd::is_trivially_copy_assignable<typename ::boost::container::iterator_traits<O>::value_type>::value
+ > use_memmove;
+
+ return copy_dispatch(first, last, dst, use_memmove()); // may throw
+}
+
+// uninitialized_copy(I, I, O)
+
+template <typename I, typename O>
+inline
+O uninitialized_copy_dispatch(I first, I last, O dst,
+ bcd::true_type const& /*use_memcpy*/)
+{
+ typedef typename ::boost::container::iterator_traits<I>::value_type value_type;
+ const std::size_t d = boost::container::iterator_distance(first, last);
+ ::memcpy(boost::container::dtl::addressof(*dst), boost::container::dtl::addressof(*first), sizeof(value_type) * d);
+ return dst + d;
+}
+
+template <typename I, typename F>
+inline
+F uninitialized_copy_dispatch(I first, I last, F dst,
+ bcd::false_type const& /*use_memcpy*/)
+{
+ return std::uninitialized_copy(first, last, dst); // may throw
+}
+
+template <typename I, typename F>
+inline
+F uninitialized_copy(I first, I last, F dst)
+{
+ typedef bcd::bool_
+ < are_corresponding<I, F>::value &&
+ bcd::is_trivially_copy_constructible<typename ::boost::container::iterator_traits<F>::value_type>::value
+ > use_memcpy;
+ return uninitialized_copy_dispatch(first, last, dst, use_memcpy()); // may throw
+}
+
+// uninitialized_move(I, I, O)
+
+template <typename I, typename O>
+inline
+O uninitialized_move_dispatch(I first, I last, O dst,
+ bcd::true_type const& /*use_memcpy*/)
+{
+ typedef typename ::boost::container::iterator_traits<I>::value_type value_type;
+ const std::size_t d = boost::container::iterator_distance(first, last);
+ ::memcpy(boost::container::dtl::addressof(*dst), boost::container::dtl::addressof(*first), sizeof(value_type) * d);
+ return dst + d;
+}
+
+template <typename I, typename O>
+inline
+O uninitialized_move_dispatch(I first, I last, O dst,
+ bcd::false_type const& /*use_memcpy*/)
+{
+ //return boost::uninitialized_move(first, last, dst); // may throw
+
+ O o = dst;
+
+ BOOST_TRY
+ {
+ typedef typename boost::container::iterator_traits<O>::value_type value_type;
+ for (; first != last; ++first, ++o )
+ new (boost::container::dtl::addressof(*o)) value_type(boost::move(*first));
+ }
+ BOOST_CATCH(...)
+ {
+ destroy(dst, o);
+ BOOST_RETHROW;
+ }
+ BOOST_CATCH_END
+
+ return dst;
+}
+
+template <typename I, typename O>
+inline
+O uninitialized_move(I first, I last, O dst)
+{
+ typedef bcd::bool_
+ < are_corresponding<I, O>::value &&
+ bcd::is_trivially_copy_constructible<typename ::boost::container::iterator_traits<O>::value_type>::value
+ > use_memcpy;
+ return uninitialized_move_dispatch(first, last, dst, use_memcpy()); // may throw
+}
+
+// TODO - move uses memmove - implement 2nd version using memcpy?
+
+// move(I, I, O)
+
+template <typename I, typename O>
+inline
+O move_dispatch(I first, I last, O dst,
+ bcd::true_type const& /*use_memmove*/)
+{
+ typedef typename ::boost::container::iterator_traits<I>::value_type value_type;
+ const std::size_t d = boost::container::iterator_distance(first, last);
+ ::memmove(boost::container::dtl::addressof(*dst), boost::container::dtl::addressof(*first), sizeof(value_type)*d );
+ return dst + d;
+}
+
+template <typename I, typename O>
+inline
+O move_dispatch(I first, I last, O dst,
+ bcd::false_type const& /*use_memmove*/)
+{
+ return boost::move(first, last, dst); // may throw
+}
+
+template <typename I, typename O>
+inline
+O move(I first, I last, O dst)
+{
+ typedef bcd::bool_
+ < are_corresponding<I, O>::value &&
+ bcd::is_trivially_copy_constructible<typename ::boost::container::iterator_traits<O>::value_type>::value
+ > use_memmove;
+ return move_dispatch(first, last, dst, use_memmove()); // may throw
+}
+
+// move_backward(BDI, BDI, BDO)
+
+template <typename BDI, typename BDO>
+inline
+BDO move_backward_dispatch(BDI first, BDI last, BDO dst,
+ bcd::true_type const& /*use_memmove*/)
+{
+ typedef typename ::boost::container::iterator_traits<BDI>::value_type value_type;
+ const std::size_t d = boost::container::iterator_distance(first, last);
+ BDO foo(dst - d);
+ ::memmove(boost::container::dtl::addressof(*foo), boost::container::dtl::addressof(*first), sizeof(value_type) * d);
+ return foo;
+}
+
+template <typename BDI, typename BDO>
+inline
+BDO move_backward_dispatch(BDI first, BDI last, BDO dst,
+ bcd::false_type const& /*use_memmove*/)
+{
+ return boost::move_backward(first, last, dst); // may throw
+}
+
+template <typename BDI, typename BDO>
+inline
+BDO move_backward(BDI first, BDI last, BDO dst)
+{
+ typedef bcd::bool_
+ < are_corresponding<BDI, BDO>::value &&
+ bcd::is_trivially_copy_constructible<typename ::boost::container::iterator_traits<BDO>::value_type>::value
+ > use_memmove;
+ return move_backward_dispatch(first, last, dst, use_memmove()); // may throw
+}
+
+template <typename T>
+struct has_nothrow_move : public
+ bcd::bool_<
+ ::boost::has_nothrow_move<
+ typename bcd::remove_const<T>::type
+ >::value
+ ||
+ ::boost::has_nothrow_move<T>::value
+ >
+{};
+
+// uninitialized_move_if_noexcept(I, I, O)
+
+template <typename I, typename O>
+inline
+O uninitialized_move_if_noexcept_dispatch(I first, I last, O dst, bcd::true_type const& /*use_move*/)
+{ return uninitialized_move(first, last, dst); }
+
+template <typename I, typename O>
+inline
+O uninitialized_move_if_noexcept_dispatch(I first, I last, O dst, bcd::false_type const& /*use_move*/)
+{ return uninitialized_copy(first, last, dst); }
+
+template <typename I, typename O>
+inline
+O uninitialized_move_if_noexcept(I first, I last, O dst)
+{
+ typedef has_nothrow_move<
+ typename ::boost::container::iterator_traits<O>::value_type
+ > use_move;
+
+ return uninitialized_move_if_noexcept_dispatch(first, last, dst, use_move()); // may throw
+}
+
+// move_if_noexcept(I, I, O)
+
+template <typename I, typename O>
+inline
+O move_if_noexcept_dispatch(I first, I last, O dst, bcd::true_type const& /*use_move*/)
+{ return move(first, last, dst); }
+
+template <typename I, typename O>
+inline
+O move_if_noexcept_dispatch(I first, I last, O dst, bcd::false_type const& /*use_move*/)
+{ return copy(first, last, dst); }
+
+template <typename I, typename O>
+inline
+O move_if_noexcept(I first, I last, O dst)
+{
+ typedef has_nothrow_move<
+ typename ::boost::container::iterator_traits<O>::value_type
+ > use_move;
+
+ return move_if_noexcept_dispatch(first, last, dst, use_move()); // may throw
+}
+
+// uninitialized_fill(I, I)
+
+template <typename I>
+inline
+void uninitialized_fill_dispatch(I first, I last,
+ bcd::true_type const& /*is_trivially_default_constructible*/,
+ bcd::true_type const& /*disable_trivial_init*/)
+{}
+
+template <typename I>
+inline
+void uninitialized_fill_dispatch(I first, I last,
+ bcd::true_type const& /*is_trivially_default_constructible*/,
+ bcd::false_type const& /*disable_trivial_init*/)
+{
+ typedef typename ::boost::container::iterator_traits<I>::value_type value_type;
+ for ( ; first != last ; ++first )
+ new (boost::container::dtl::addressof(*first)) value_type();
+}
+
+template <typename I, typename DisableTrivialInit>
+inline
+void uninitialized_fill_dispatch(I first, I last,
+ bcd::false_type const& /*is_trivially_default_constructible*/,
+ DisableTrivialInit const& /*not_used*/)
+{
+ typedef typename ::boost::container::iterator_traits<I>::value_type value_type;
+ I it = first;
+
+ BOOST_TRY
+ {
+ for ( ; it != last ; ++it )
+ new (boost::container::dtl::addressof(*it)) value_type(); // may throw
+ }
+ BOOST_CATCH(...)
+ {
+ destroy(first, it);
+ BOOST_RETHROW;
+ }
+ BOOST_CATCH_END
+}
+
+template <typename I, typename DisableTrivialInit>
+inline
+void uninitialized_fill(I first, I last, DisableTrivialInit const& disable_trivial_init)
+{
+ typedef typename ::boost::container::iterator_traits<I>::value_type value_type;
+ uninitialized_fill_dispatch(first, last
+ , bcd::bool_<bcd::is_trivially_default_constructible<value_type>::value>()
+ , disable_trivial_init); // may throw
+}
+
+// construct(I)
+
+template <typename I>
+inline
+void construct_dispatch(bcd::true_type const& /*dont_init*/, I pos)
+{}
+
+template <typename I>
+inline
+void construct_dispatch(bcd::false_type const& /*dont_init*/, I pos)
+{
+ typedef typename ::boost::container::iterator_traits<I>::value_type value_type;
+ new (static_cast<void*>(::boost::container::dtl::addressof(*pos))) value_type(); // may throw
+}
+
+template <typename DisableTrivialInit, typename I>
+inline
+void construct(DisableTrivialInit const&, I pos)
+{
+ typedef typename ::boost::container::iterator_traits<I>::value_type value_type;
+ bcd::bool_<
+ bcd::is_trivially_default_constructible<value_type>::value &&
+ DisableTrivialInit::value
+ > dont_init;
+ construct_dispatch(dont_init(), pos); // may throw
+}
+
+// construct(I, V)
+
+template <typename I, typename V>
+inline
+void construct_dispatch(I pos, V const& v, bcd::true_type const& /*use_memcpy*/)
+{
+ ::memcpy(boost::container::dtl::addressof(*pos), boost::container::dtl::addressof(v), sizeof(V));
+}
+
+template <typename I, typename P>
+inline
+void construct_dispatch(I pos, P const& p,
+ bcd::false_type const& /*use_memcpy*/)
+{
+ typedef typename ::boost::container::iterator_traits<I>::value_type V;
+ new (static_cast<void*>(boost::container::dtl::addressof(*pos))) V(p); // may throw
+}
+
+template <typename DisableTrivialInit, typename I, typename P>
+inline
+void construct(DisableTrivialInit const&, I pos, P const& p)
+{
+ typedef bcd::bool_
+ < is_corresponding_value<I, P>::value &&
+ bcd::is_trivially_copy_constructible<P>::value
+ > use_memcpy;
+ construct_dispatch(pos, p, use_memcpy()); // may throw
+}
+
+// Needed by push_back(V &&)
+
+template <typename DisableTrivialInit, typename I, typename P>
+inline
+void construct(DisableTrivialInit const&, I pos, BOOST_RV_REF(P) p)
+{
+ typedef typename ::boost::container::iterator_traits<I>::value_type V;
+ new (static_cast<void*>(boost::container::dtl::addressof(*pos))) V(::boost::move(p)); // may throw
+}
+
+// Needed by emplace_back() and emplace()
+
+#if !defined(BOOST_CONTAINER_VARRAY_DISABLE_EMPLACE)
+#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
+
+template <typename DisableTrivialInit, typename I, class ...Args>
+inline
+void construct(DisableTrivialInit const&,
+ I pos,
+ BOOST_FWD_REF(Args) ...args)
+{
+ typedef typename ::boost::container::iterator_traits<I>::value_type V;
+ new (static_cast<void*>(boost::container::dtl::addressof(*pos))) V(::boost::forward<Args>(args)...); // may throw
+}
+
+#else // !BOOST_NO_CXX11_VARIADIC_TEMPLATES
+
+// BOOST_NO_CXX11_RVALUE_REFERENCES -> P0 const& p0
+// !BOOST_NO_CXX11_RVALUE_REFERENCES -> P0 && p0
+// which means that version with one parameter may take V const& v
+
+#define BOOST_CONTAINER_VARRAY_UTIL_CONSTRUCT_CODE(N) \
+template <typename DisableTrivialInit, typename I, typename P BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
+inline void construct(DisableTrivialInit const&, I pos, BOOST_FWD_REF(P) p BOOST_MOVE_I##N BOOST_MOVE_UREF##N )\
+{\
+ typedef typename ::boost::container::iterator_traits<I>::value_type V;\
+ new (static_cast<void*>(boost::container::dtl::addressof(*pos)))\
+ V(::boost::forward<P>(p) BOOST_MOVE_I##N BOOST_MOVE_FWD##N); /*may throw*/\
+}
+BOOST_MOVE_ITERATE_1TO9(BOOST_CONTAINER_VARRAY_UTIL_CONSTRUCT_CODE)
+#undef BOOST_CONTAINER_VARRAY_UTIL_CONSTRUCT_CODE
+
+#endif // !BOOST_NO_CXX11_VARIADIC_TEMPLATES
+#endif // !BOOST_CONTAINER_VARRAY_DISABLE_EMPLACE
+
+// assign(I, V)
+
+template <typename I, typename V>
+inline
+void assign_dispatch(I pos, V const& v,
+ bcd::true_type const& /*use_memcpy*/)
+{
+ ::memcpy(boost::container::dtl::addressof(*pos), boost::container::dtl::addressof(v), sizeof(V));
+}
+
+template <typename I, typename V>
+inline
+void assign_dispatch(I pos, V const& v,
+ bcd::false_type const& /*use_memcpy*/)
+{
+ *pos = v; // may throw
+}
+
+template <typename I, typename V>
+inline
+void assign(I pos, V const& v)
+{
+ typedef bcd::bool_
+ < is_corresponding_value<I, V>::value &&
+ bcd::is_trivially_copy_assignable<V>::value
+ > use_memcpy;
+ assign_dispatch(pos, v, use_memcpy()); // may throw
+}
+
+template <typename I, typename V>
+inline
+void assign(I pos, BOOST_RV_REF(V) v)
+{
+ *pos = boost::move(v); // may throw
+}
+
+
+// uninitialized_copy_s
+
+template <typename I, typename F>
+inline std::size_t uninitialized_copy_s(I first, I last, F dest, std::size_t max_count)
+{
+ std::size_t count = 0;
+ F it = dest;
+
+ BOOST_TRY
+ {
+ for ( ; first != last ; ++it, ++first, ++count )
+ {
+ if ( max_count <= count )
+ return (std::numeric_limits<std::size_t>::max)();
+
+ // dummy 0 as DisableTrivialInit
+ construct(0, it, *first); // may throw
+ }
+ }
+ BOOST_CATCH(...)
+ {
+ destroy(dest, it);
+ BOOST_RETHROW;
+ }
+ BOOST_CATCH_END
+
+ return count;
+}
+
+// scoped_destructor
+
+template<class T>
+class scoped_destructor
+{
+public:
+ scoped_destructor(T * ptr) : m_ptr(ptr) {}
+
+ ~scoped_destructor()
+ {
+ if(m_ptr)
+ destroy(m_ptr);
+ }
+
+ void release() { m_ptr = 0; }
+
+private:
+ T * m_ptr;
+};
+
+}}} // namespace boost::container::varray_detail
+
+#endif // BOOST_CONTAINER_DETAIL_VARRAY_UTIL_HPP
diff --git a/bench/varray.hpp b/bench/varray.hpp
new file mode 100644
index 0000000..98b7100
--- /dev/null
+++ b/bench/varray.hpp
@@ -0,0 +1,1000 @@
+// Boost.Container varray
+//
+// Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
+// Copyright (c) 2011-2013 Andrew Hundt.
+// Copyright (c) 2014-2014 Ion Gaztanaga
+//
+// Use, modification and distribution is subject to 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)
+
+#ifndef BOOST_CONTAINER_VARRAY_HPP
+#define BOOST_CONTAINER_VARRAY_HPP
+
+#ifndef BOOST_CONFIG_HPP
+# include <boost/config.hpp>
+#endif
+
+#if defined(BOOST_HAS_PRAGMA_ONCE)
+# pragma once
+#endif
+
+#include <boost/container/detail/config_begin.hpp>
+
+#include "detail/varray.hpp"
+#include <boost/move/utility_core.hpp>
+
+namespace boost { namespace container {
+
+/**
+ * @defgroup varray_non_member varray non-member functions
+ */
+
+/**
+ * @brief A variable-size array container with fixed capacity.
+ *
+ * varray is a sequence container like boost::container::vector with contiguous storage that can
+ * change in size, along with the static allocation, low overhead, and fixed capacity of boost::array.
+ *
+ * A varray is a sequence that supports random access to elements, constant time insertion and
+ * removal of elements at the end, and linear time insertion and removal of elements at the beginning or
+ * in the middle. The number of elements in a varray may vary dynamically up to a fixed capacity
+ * because elements are stored within the object itself similarly to an array. However, objects are
+ * initialized as they are inserted into varray unlike C arrays or std::array which must construct
+ * all elements on instantiation. The behavior of varray enables the use of statically allocated
+ * elements in cases with complex object lifetime requirements that would otherwise not be trivially
+ * possible.
+ *
+ * @par Error Handling
+ * Insertion beyond the capacity and out of bounds errors result in undefined behavior.
+ * The reason for this is because unlike vectors, varray does not perform allocation.
+ *
+ * @tparam Value The type of element that will be stored.
+ * @tparam Capacity The maximum number of elements varray can store, fixed at compile time.
+ */
+template <typename Value, std::size_t Capacity>
+class varray
+ : public dtl::varray<Value, Capacity>
+{
+ typedef dtl::varray<Value, Capacity> base_t;
+
+ BOOST_COPYABLE_AND_MOVABLE(varray)
+
+public:
+ //! @brief The type of elements stored in the container.
+ typedef typename base_t::value_type value_type;
+ //! @brief The unsigned integral type used by the container.
+ typedef typename base_t::size_type size_type;
+ //! @brief The pointers difference type.
+ typedef typename base_t::difference_type difference_type;
+ //! @brief The pointer type.
+ typedef typename base_t::pointer pointer;
+ //! @brief The const pointer type.
+ typedef typename base_t::const_pointer const_pointer;
+ //! @brief The value reference type.
+ typedef typename base_t::reference reference;
+ //! @brief The value const reference type.
+ typedef typename base_t::const_reference const_reference;
+ //! @brief The iterator type.
+ typedef typename base_t::iterator iterator;
+ //! @brief The const iterator type.
+ typedef typename base_t::const_iterator const_iterator;
+ //! @brief The reverse iterator type.
+ typedef typename base_t::reverse_iterator reverse_iterator;
+ //! @brief The const reverse iterator.
+ typedef typename base_t::const_reverse_iterator const_reverse_iterator;
+
+ //! @brief Constructs an empty varray.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ varray()
+ : base_t()
+ {}
+
+ //! @pre <tt>count <= capacity()</tt>
+ //!
+ //! @brief Constructs a varray containing count value initialized Values.
+ //!
+ //! @param count The number of values which will be contained in the container.
+ //!
+ //! @par Throws
+ //! If Value's value initialization throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ explicit varray(size_type count)
+ : base_t(count)
+ {}
+
+ //! @pre <tt>count <= capacity()</tt>
+ //!
+ //! @brief Constructs a varray containing count copies of value.
+ //!
+ //! @param count The number of copies of a values that will be contained in the container.
+ //! @param value The value which will be used to copy construct values.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ varray(size_type count, value_type const& value)
+ : base_t(count, value)
+ {}
+
+ //! @pre
+ //! @li <tt>distance(first, last) <= capacity()</tt>
+ //! @li Iterator must meet the \c ForwardTraversalIterator concept.
+ //!
+ //! @brief Constructs a varray containing copy of a range <tt>[first, last)</tt>.
+ //!
+ //! @param first The iterator to the first element in range.
+ //! @param last The iterator to the one after the last element in range.
+ //!
+ //! @par Throws
+ //! If Value's constructor taking a dereferenced Iterator throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ template <typename Iterator>
+ varray(Iterator first, Iterator last)
+ : base_t(first, last)
+ {}
+
+ //! @brief Constructs a copy of other varray.
+ //!
+ //! @param other The varray which content will be copied to this one.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ varray(varray const& other)
+ : base_t(other)
+ {}
+
+ //! @pre <tt>other.size() <= capacity()</tt>.
+ //!
+ //! @brief Constructs a copy of other varray.
+ //!
+ //! @param other The varray which content will be copied to this one.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ template <std::size_t C>
+ varray(varray<value_type, C> const& other) : base_t(other) {}
+
+ //! @brief Copy assigns Values stored in the other varray to this one.
+ //!
+ //! @param other The varray which content will be copied to this one.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor or copy assignment throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ varray & operator=(BOOST_COPY_ASSIGN_REF(varray) other)
+ {
+ base_t::operator=(static_cast<base_t const&>(other));
+ return *this;
+ }
+
+ //! @pre <tt>other.size() <= capacity()</tt>
+ //!
+ //! @brief Copy assigns Values stored in the other varray to this one.
+ //!
+ //! @param other The varray which content will be copied to this one.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor or copy assignment throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ template <std::size_t C>
+// TEMPORARY WORKAROUND
+#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
+ varray & operator=(::boost::rv< varray<value_type, C> > const& other)
+#else
+ varray & operator=(varray<value_type, C> const& other)
+#endif
+ {
+ base_t::operator=(static_cast<varray<value_type, C> const&>(other));
+ return *this;
+ }
+
+ //! @brief Move constructor. Moves Values stored in the other varray to this one.
+ //!
+ //! @param other The varray which content will be moved to this one.
+ //!
+ //! @par Throws
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor throws.
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ varray(BOOST_RV_REF(varray) other)
+ : base_t(boost::move(static_cast<base_t&>(other)))
+ {}
+
+ //! @pre <tt>other.size() <= capacity()</tt>
+ //!
+ //! @brief Move constructor. Moves Values stored in the other varray to this one.
+ //!
+ //! @param other The varray which content will be moved to this one.
+ //!
+ //! @par Throws
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor throws.
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ template <std::size_t C>
+ varray(BOOST_RV_REF_2_TEMPL_ARGS(varray, value_type, C) other)
+ : base_t(boost::move(static_cast<dtl::varray<value_type, C>&>(other)))
+ {}
+
+ //! @brief Move assignment. Moves Values stored in the other varray to this one.
+ //!
+ //! @param other The varray which content will be moved to this one.
+ //!
+ //! @par Throws
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws.
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ varray & operator=(BOOST_RV_REF(varray) other)
+ {
+ base_t::operator=(boost::move(static_cast<base_t&>(other)));
+ return *this;
+ }
+
+ //! @pre <tt>other.size() <= capacity()</tt>
+ //!
+ //! @brief Move assignment. Moves Values stored in the other varray to this one.
+ //!
+ //! @param other The varray which content will be moved to this one.
+ //!
+ //! @par Throws
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws.
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ template <std::size_t C>
+ varray & operator=(BOOST_RV_REF_2_TEMPL_ARGS(varray, value_type, C) other)
+ {
+ base_t::operator=(boost::move(static_cast<dtl::varray<value_type, C>&>(other)));
+ return *this;
+ }
+
+#ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
+
+ //! @brief Destructor. Destroys Values stored in this container.
+ //!
+ //! @par Throws
+ //! Nothing
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ ~varray();
+
+ //! @brief Swaps contents of the other varray and this one.
+ //!
+ //! @param other The varray which content will be swapped with this one's content.
+ //!
+ //! @par Throws
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws,
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws,
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ void swap(varray & other);
+
+ //! @pre <tt>other.size() <= capacity() && size() <= other.capacity()</tt>
+ //!
+ //! @brief Swaps contents of the other varray and this one.
+ //!
+ //! @param other The varray which content will be swapped with this one's content.
+ //!
+ //! @par Throws
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c true and Value's move constructor or move assignment throws,
+ //! @li If \c boost::has_nothrow_move<Value>::value is \c false and Value's copy constructor or copy assignment throws,
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ template <std::size_t C>
+ void swap(varray<value_type, C> & other);
+
+ //! @pre <tt>count <= capacity()</tt>
+ //!
+ //! @brief Inserts or erases elements at the end such that
+ //! the size becomes count. New elements are value initialized.
+ //!
+ //! @param count The number of elements which will be stored in the container.
+ //!
+ //! @par Throws
+ //! If Value's value initialization throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ void resize(size_type count);
+
+ //! @pre <tt>count <= capacity()</tt>
+ //!
+ //! @brief Inserts or erases elements at the end such that
+ //! the size becomes count. New elements are copy constructed from value.
+ //!
+ //! @param count The number of elements which will be stored in the container.
+ //! @param value The value used to copy construct the new element.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ void resize(size_type count, value_type const& value);
+
+ //! @pre <tt>count <= capacity()</tt>
+ //!
+ //! @brief This call has no effect because the Capacity of this container is constant.
+ //!
+ //! @param count The number of elements which the container should be able to contain.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ void reserve(size_type count);
+
+ //! @pre <tt>size() < capacity()</tt>
+ //!
+ //! @brief Adds a copy of value at the end.
+ //!
+ //! @param value The value used to copy construct the new element.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor throws.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ void push_back(value_type const& value);
+
+ //! @pre <tt>size() < capacity()</tt>
+ //!
+ //! @brief Moves value to the end.
+ //!
+ //! @param value The value to move construct the new element.
+ //!
+ //! @par Throws
+ //! If Value's move constructor throws.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ void push_back(BOOST_RV_REF(value_type) value);
+
+ //! @pre <tt>!empty()</tt>
+ //!
+ //! @brief Destroys last value and decreases the size.
+ //!
+ //! @par Throws
+ //! Nothing by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ void pop_back();
+
+ //! @pre
+ //! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
+ //! @li <tt>size() < capacity()</tt>
+ //!
+ //! @brief Inserts a copy of element at position.
+ //!
+ //! @param position The position at which the new value will be inserted.
+ //! @param value The value used to copy construct the new element.
+ //!
+ //! @par Throws
+ //! @li If Value's copy constructor or copy assignment throws
+ //! @li If Value's move constructor or move assignment throws.
+ //!
+ //! @par Complexity
+ //! Constant or linear.
+ iterator insert(iterator position, value_type const& value);
+
+ //! @pre
+ //! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
+ //! @li <tt>size() < capacity()</tt>
+ //!
+ //! @brief Inserts a move-constructed element at position.
+ //!
+ //! @param position The position at which the new value will be inserted.
+ //! @param value The value used to move construct the new element.
+ //!
+ //! @par Throws
+ //! If Value's move constructor or move assignment throws.
+ //!
+ //! @par Complexity
+ //! Constant or linear.
+ iterator insert(iterator position, BOOST_RV_REF(value_type) value);
+
+ //! @pre
+ //! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
+ //! @li <tt>size() + count <= capacity()</tt>
+ //!
+ //! @brief Inserts a count copies of value at position.
+ //!
+ //! @param position The position at which new elements will be inserted.
+ //! @param count The number of new elements which will be inserted.
+ //! @param value The value used to copy construct new elements.
+ //!
+ //! @par Throws
+ //! @li If Value's copy constructor or copy assignment throws.
+ //! @li If Value's move constructor or move assignment throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ iterator insert(iterator position, size_type count, value_type const& value);
+
+ //! @pre
+ //! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>.
+ //! @li <tt>distance(first, last) <= capacity()</tt>
+ //! @li \c Iterator must meet the \c ForwardTraversalIterator concept.
+ //!
+ //! @brief Inserts a copy of a range <tt>[first, last)</tt> at position.
+ //!
+ //! @param position The position at which new elements will be inserted.
+ //! @param first The iterator to the first element of a range used to construct new elements.
+ //! @param last The iterator to the one after the last element of a range used to construct new elements.
+ //!
+ //! @par Throws
+ //! @li If Value's constructor and assignment taking a dereferenced \c Iterator.
+ //! @li If Value's move constructor or move assignment throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ template <typename Iterator>
+ iterator insert(iterator position, Iterator first, Iterator last);
+
+ //! @pre \c position must be a valid iterator of \c *this in range <tt>[begin(), end())</tt>
+ //!
+ //! @brief Erases Value from position.
+ //!
+ //! @param position The position of the element which will be erased from the container.
+ //!
+ //! @par Throws
+ //! If Value's move assignment throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ iterator erase(iterator position);
+
+ //! @pre
+ //! @li \c first and \c last must define a valid range
+ //! @li iterators must be in range <tt>[begin(), end()]</tt>
+ //!
+ //! @brief Erases Values from a range <tt>[first, last)</tt>.
+ //!
+ //! @param first The position of the first element of a range which will be erased from the container.
+ //! @param last The position of the one after the last element of a range which will be erased from the container.
+ //!
+ //! @par Throws
+ //! If Value's move assignment throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ iterator erase(iterator first, iterator last);
+
+ //! @pre <tt>distance(first, last) <= capacity()</tt>
+ //!
+ //! @brief Assigns a range <tt>[first, last)</tt> of Values to this container.
+ //!
+ //! @param first The iterator to the first element of a range used to construct new content of this container.
+ //! @param last The iterator to the one after the last element of a range used to construct new content of this container.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor or copy assignment throws,
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ template <typename Iterator>
+ void assign(Iterator first, Iterator last);
+
+ //! @pre <tt>count <= capacity()</tt>
+ //!
+ //! @brief Assigns a count copies of value to this container.
+ //!
+ //! @param count The new number of elements which will be container in the container.
+ //! @param value The value which will be used to copy construct the new content.
+ //!
+ //! @par Throws
+ //! If Value's copy constructor or copy assignment throws.
+ //!
+ //! @par Complexity
+ //! Linear O(N).
+ void assign(size_type count, value_type const& value);
+
+ //! @pre <tt>size() < capacity()</tt>
+ //!
+ //! @brief Inserts a Value constructed with
+ //! \c std::forward<Args>(args)... in the end of the container.
+ //!
+ //! @param args The arguments of the constructor of the new element which will be created at the end of the container.
+ //!
+ //! @par Throws
+ //! If in-place constructor throws or Value's move constructor throws.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ template<class ...Args>
+ void emplace_back(Args &&...args);
+
+ //! @pre
+ //! @li \c position must be a valid iterator of \c *this in range <tt>[begin(), end()]</tt>
+ //! @li <tt>size() < capacity()</tt>
+ //!
+ //! @brief Inserts a Value constructed with
+ //! \c std::forward<Args>(args)... before position
+ //!
+ //! @param position The position at which new elements will be inserted.
+ //! @param args The arguments of the constructor of the new element.
+ //!
+ //! @par Throws
+ //! If in-place constructor throws or if Value's move constructor or move assignment throws.
+ //!
+ //! @par Complexity
+ //! Constant or linear.
+ template<class ...Args>
+ iterator emplace(iterator position, Args &&...args);
+
+ //! @brief Removes all elements from the container.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ void clear();
+
+ //! @pre <tt>i < size()</tt>
+ //!
+ //! @brief Returns reference to the i-th element.
+ //!
+ //! @param i The element's index.
+ //!
+ //! @return reference to the i-th element
+ //! from the beginning of the container.
+ //!
+ //! @par Throws
+ //! \c std::out_of_range exception by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ reference at(size_type i);
+
+ //! @pre <tt>i < size()</tt>
+ //!
+ //! @brief Returns const reference to the i-th element.
+ //!
+ //! @param i The element's index.
+ //!
+ //! @return const reference to the i-th element
+ //! from the beginning of the container.
+ //!
+ //! @par Throws
+ //! \c std::out_of_range exception by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_reference at(size_type i) const;
+
+ //! @pre <tt>i < size()</tt>
+ //!
+ //! @brief Returns reference to the i-th element.
+ //!
+ //! @param i The element's index.
+ //!
+ //! @return reference to the i-th element
+ //! from the beginning of the container.
+ //!
+ //! @par Throws
+ //! Nothing by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ reference operator[](size_type i);
+
+ //! @pre <tt>i < size()</tt>
+ //!
+ //! @brief Returns const reference to the i-th element.
+ //!
+ //! @param i The element's index.
+ //!
+ //! @return const reference to the i-th element
+ //! from the beginning of the container.
+ //!
+ //! @par Throws
+ //! Nothing by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_reference operator[](size_type i) const;
+
+ //! @pre \c !empty()
+ //!
+ //! @brief Returns reference to the first element.
+ //!
+ //! @return reference to the first element
+ //! from the beginning of the container.
+ //!
+ //! @par Throws
+ //! Nothing by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ reference front();
+
+ //! @pre \c !empty()
+ //!
+ //! @brief Returns const reference to the first element.
+ //!
+ //! @return const reference to the first element
+ //! from the beginning of the container.
+ //!
+ //! @par Throws
+ //! Nothing by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_reference front() const;
+
+ //! @pre \c !empty()
+ //!
+ //! @brief Returns reference to the last element.
+ //!
+ //! @return reference to the last element
+ //! from the beginning of the container.
+ //!
+ //! @par Throws
+ //! Nothing by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ reference back();
+
+ //! @pre \c !empty()
+ //!
+ //! @brief Returns const reference to the first element.
+ //!
+ //! @return const reference to the last element
+ //! from the beginning of the container.
+ //!
+ //! @par Throws
+ //! Nothing by default.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_reference back() const;
+
+ //! @brief Pointer such that <tt>[data(), data() + size())</tt> is a valid range.
+ //! For a non-empty vector <tt>data() == &front()</tt>.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ Value * data();
+
+ //! @brief Const pointer such that <tt>[data(), data() + size())</tt> is a valid range.
+ //! For a non-empty vector <tt>data() == &front()</tt>.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const Value * data() const;
+
+ //! @brief Returns iterator to the first element.
+ //!
+ //! @return iterator to the first element contained in the vector.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ iterator begin();
+
+ //! @brief Returns const iterator to the first element.
+ //!
+ //! @return const_iterator to the first element contained in the vector.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_iterator begin() const;
+
+ //! @brief Returns const iterator to the first element.
+ //!
+ //! @return const_iterator to the first element contained in the vector.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_iterator cbegin() const;
+
+ //! @brief Returns iterator to the one after the last element.
+ //!
+ //! @return iterator pointing to the one after the last element contained in the vector.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ iterator end();
+
+ //! @brief Returns const iterator to the one after the last element.
+ //!
+ //! @return const_iterator pointing to the one after the last element contained in the vector.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_iterator end() const;
+
+ //! @brief Returns const iterator to the one after the last element.
+ //!
+ //! @return const_iterator pointing to the one after the last element contained in the vector.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_iterator cend() const;
+
+ //! @brief Returns reverse iterator to the first element of the reversed container.
+ //!
+ //! @return reverse_iterator pointing to the beginning
+ //! of the reversed varray.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ reverse_iterator rbegin();
+
+ //! @brief Returns const reverse iterator to the first element of the reversed container.
+ //!
+ //! @return const_reverse_iterator pointing to the beginning
+ //! of the reversed varray.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_reverse_iterator rbegin() const;
+
+ //! @brief Returns const reverse iterator to the first element of the reversed container.
+ //!
+ //! @return const_reverse_iterator pointing to the beginning
+ //! of the reversed varray.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_reverse_iterator crbegin() const;
+
+ //! @brief Returns reverse iterator to the one after the last element of the reversed container.
+ //!
+ //! @return reverse_iterator pointing to the one after the last element
+ //! of the reversed varray.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ reverse_iterator rend();
+
+ //! @brief Returns const reverse iterator to the one after the last element of the reversed container.
+ //!
+ //! @return const_reverse_iterator pointing to the one after the last element
+ //! of the reversed varray.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_reverse_iterator rend() const;
+
+ //! @brief Returns const reverse iterator to the one after the last element of the reversed container.
+ //!
+ //! @return const_reverse_iterator pointing to the one after the last element
+ //! of the reversed varray.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ const_reverse_iterator crend() const;
+
+ //! @brief Returns container's capacity.
+ //!
+ //! @return container's capacity.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ static size_type capacity();
+
+ //! @brief Returns container's capacity.
+ //!
+ //! @return container's capacity.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ static size_type max_size();
+
+ //! @brief Returns the number of stored elements.
+ //!
+ //! @return Number of elements contained in the container.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ size_type size() const;
+
+ //! @brief Queries if the container contains elements.
+ //!
+ //! @return true if the number of elements contained in the
+ //! container is equal to 0.
+ //!
+ //! @par Throws
+ //! Nothing.
+ //!
+ //! @par Complexity
+ //! Constant O(1).
+ bool empty() const;
+
+#endif // BOOST_CONTAINER_DOXYGEN_INVOKED
+
+};
+
+#ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
+
+//! @brief Checks if contents of two varrays are equal.
+//!
+//! @ingroup varray_non_member
+//!
+//! @param x The first varray.
+//! @param y The second varray.
+//!
+//! @return \c true if containers have the same size and elements in both containers are equal.
+//!
+//! @par Complexity
+//! Linear O(N).
+template<typename V, std::size_t C1, std::size_t C2>
+bool operator== (varray<V, C1> const& x, varray<V, C2> const& y);
+
+//! @brief Checks if contents of two varrays are not equal.
+//!
+//! @ingroup varray_non_member
+//!
+//! @param x The first varray.
+//! @param y The second varray.
+//!
+//! @return \c true if containers have different size or elements in both containers are not equal.
+//!
+//! @par Complexity
+//! Linear O(N).
+template<typename V, std::size_t C1, std::size_t C2>
+bool operator!= (varray<V, C1> const& x, varray<V, C2> const& y);
+
+//! @brief Lexicographically compares varrays.
+//!
+//! @ingroup varray_non_member
+//!
+//! @param x The first varray.
+//! @param y The second varray.
+//!
+//! @return \c true if x compares lexicographically less than y.
+//!
+//! @par Complexity
+//! Linear O(N).
+template<typename V, std::size_t C1, std::size_t C2>
+bool operator< (varray<V, C1> const& x, varray<V, C2> const& y);
+
+//! @brief Lexicographically compares varrays.
+//!
+//! @ingroup varray_non_member
+//!
+//! @param x The first varray.
+//! @param y The second varray.
+//!
+//! @return \c true if y compares lexicographically less than x.
+//!
+//! @par Complexity
+//! Linear O(N).
+template<typename V, std::size_t C1, std::size_t C2>
+bool operator> (varray<V, C1> const& x, varray<V, C2> const& y);
+
+//! @brief Lexicographically compares varrays.
+//!
+//! @ingroup varray_non_member
+//!
+//! @param x The first varray.
+//! @param y The second varray.
+//!
+//! @return \c true if y don't compare lexicographically less than x.
+//!
+//! @par Complexity
+//! Linear O(N).
+template<typename V, std::size_t C1, std::size_t C2>
+bool operator<= (varray<V, C1> const& x, varray<V, C2> const& y);
+
+//! @brief Lexicographically compares varrays.
+//!
+//! @ingroup varray_non_member
+//!
+//! @param x The first varray.
+//! @param y The second varray.
+//!
+//! @return \c true if x don't compare lexicographically less than y.
+//!
+//! @par Complexity
+//! Linear O(N).
+template<typename V, std::size_t C1, std::size_t C2>
+bool operator>= (varray<V, C1> const& x, varray<V, C2> const& y);
+
+//! @brief Swaps contents of two varrays.
+//!
+//! This function calls varray::swap().
+//!
+//! @ingroup varray_non_member
+//!
+//! @param x The first varray.
+//! @param y The second varray.
+//!
+//! @par Complexity
+//! Linear O(N).
+template<typename V, std::size_t C1, std::size_t C2>
+inline void swap(varray<V, C1> & x, varray<V, C2> & y);
+
+#endif // BOOST_CONTAINER_DOXYGEN_INVOKED
+
+}} // namespace boost::container
+
+#include <boost/container/detail/config_end.hpp>
+
+#endif // BOOST_CONTAINER_VARRAY_HPP
diff --git a/build/Jamfile.v2 b/build/Jamfile.v2
new file mode 100644
index 0000000..3adb451
--- /dev/null
+++ b/build/Jamfile.v2
@@ -0,0 +1,22 @@
+# (C) Copyright Vladimir Prus, David Abrahams, Michael Stevens, Hartmut Kaiser,
+# Ion Gaztanaga 2007-2008
+# Use, modification and distribution are subject to 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)
+
+import sequence ;
+
+project boost/container
+ : source-location ../src
+ : usage-requirements # pass these requirement to dependents (i.e. users)
+ <link>shared:<define>BOOST_CONTAINER_DYN_LINK=1
+ <link>static:<define>BOOST_CONTAINER_STATIC_LINK=1
+ ;
+
+lib boost_container
+ : alloc_lib.c [ sequence.insertion-sort [ glob *.cpp ] ]
+ : <link>shared:<define>BOOST_CONTAINER_DYN_LINK=1
+ <link>static:<define>BOOST_CONTAINER_STATIC_LINK=1
+ ;
+
+boost-install boost_container ;
\ No newline at end of file
diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2
new file mode 100644
index 0000000..dedb9c1
--- /dev/null
+++ b/doc/Jamfile.v2
@@ -0,0 +1,118 @@
+# Boost.Container library documentation Jamfile ---------------------------------
+#
+# Copyright Ion Gaztanaga 2009-2013. Use, modification and
+# distribution is subject to 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)
+#
+# See http://www.boost.org for updates, documentation, and revision history.
+
+import doxygen ;
+import quickbook ;
+
+using auto-index ;
+
+path-constant images_location : ../ ;
+path-constant here : . ;
+
+doxygen autodoc
+ :
+ [ glob ../../../boost/container/*.hpp ]
+ [ glob ../../../boost/container/pmr/*.hpp ]
+ :
+ <doxygen:param>EXTRACT_ALL=NO
+ <doxygen:param>HIDE_UNDOC_MEMBERS=YES
+ <doxygen:param>EXTRACT_PRIVATE=NO
+ <doxygen:param>ENABLE_PREPROCESSING=YES
+ <doxygen:param>EXPAND_ONLY_PREDEF=YES
+ <doxygen:param>MACRO_EXPANSION=YES
+ <doxygen:param>"PREDEFINED=\"insert_const_ref_type= const T&\" \\
+ \"BOOST_CONSTEXPR_OR_CONST=constexpr\" \\
+ \"BOOST_CONTAINER_DOXYGEN_INVOKED\" \\
+ \"BOOST_CONTAINER_IMPDEF(T)=implementation_defined\" \\
+ \"BOOST_CONTAINER_SEEDOC(T)=see_documentation\" \\
+ \"BOOST_NOEXCEPT_OR_NOTHROW=noexcept\" \\
+ \"BOOST_NOEXCEPT_IF(T)=noexcept(T)\" \\
+ \"BOOST_RV_REF(T)=T&&\" \\
+ \"BOOST_RV_REF_BEG=\" \\
+ \"BOOST_RV_REF_END=&&\" \\
+ \"BOOST_RV_REF_BEG_IF_CXX11=\" \\
+ \"BOOST_RV_REF_END_IF_CXX11=&&\" \\
+ \"BOOST_COPY_ASSIGN_REF(T)=const T &\" \\
+ \"BOOST_FWD_REF(a)=a &&\" \\
+ \"BOOST_INTRUSIVE_OPTION_CONSTANT(OPTION_NAME, TYPE, VALUE, CONSTANT_NAME) = template<TYPE VALUE> struct OPTION_NAME{};\" \\
+ \"BOOST_INTRUSIVE_OPTION_TYPE(OPTION_NAME, TYPE, TYPEDEF_EXPR, TYPEDEF_NAME) = template<class TYPE> struct OPTION_NAME{};\" \\
+ \"BOOST_CONTAINER_DOC1ST(T1, T2)=T1\" \\
+ \"BOOST_CONTAINER_DOCIGN(T) \"\\
+ \"BOOST_CONTAINER_DOCONLY(T)=T\"\\
+ \"BOOST_CONTAINER_SCOPEDALLOC_DUMMYTRUE=\"\\
+ \"BOOST_CONTAINER_SCOPEDALLOC_ALLINNER=InnerAllocs...\"\\
+ \"BOOST_CONTAINER_DECL=\"\\
+ \"BOOST_CONTAINER_FORCEINLINE=inline\" \\
+ "
+ <xsl:param>"boost.doxygen.reftitle=Boost.Container Header Reference"
+ ;
+
+xml container : container.qbk
+ :
+ <include>../../../tools/auto_index/include
+ ;
+
+boostbook standalone
+ :
+ container
+ :
+ <format>html:<xsl:param>boost.root=../../../..
+ <format>html:<xsl:param>boost.libraries=../../../../libs/libraries.htm
+ <format>html:<xsl:param>img.src.path=../../../../doc/html/
+ <format>xhtml:<xsl:param>img.src.path=../../../../doc/html/
+ <xsl:param>generate.section.toc.level=3
+ <xsl:param>chunk.first.sections=1
+ <format>pdf:<xsl:param>img.src.path=$(images_location)/
+ <dependency>autodoc
+ <format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html
+
+ # Build requirements go here:
+
+ # <auto-index>on (or off) one turns on (or off) indexing:
+ <auto-index>on
+
+ # Turns on (or off) auto-index-verbose for diagnostic info.
+ # This is highly recommended until you have got all the many details correct!
+ <auto-index-verbose>on
+
+ # Choose the indexing method (separately for html and PDF) - see manual.
+ # Choose indexing method for PDFs:
+ <format>pdf:<auto-index-internal>off
+
+ # Choose indexing method for html:
+ <format>html:<auto-index-internal>on
+ <format>docbook:<auto-index-internal>on
+
+ # Set the name of the script file to use (index.idx is popular):
+ <auto-index-script>$(here)/index.idx
+ # Commands in the script file should all use RELATIVE PATHS
+ # otherwise the script will not be portable to other machines.
+ # Relative paths are normally taken as relative to the location
+ # of the script file, but we can add a prefix to all
+ # those relative paths using the <auto-index-prefix> feature.
+ # The path specified by <auto-index-prefix> may be either relative or
+ # absolute, for example the following will get us up to the boost root
+ # directory for most Boost libraries:
+ <auto-index-prefix>"$(here)/../../.."
+
+ <format>pdf:<xsl:param>admon.graphics.extension=".svg"
+ ;
+
+install pdfinstall : standalone/<format>pdf : <install-type>PDF <location>. <name>container.pdf ;
+explicit pdfinstall ;
+
+###############################################################################
+alias boostdoc
+ : standalone/<format>docbook
+ :
+ :
+ : ;
+explicit boostdoc ;
+alias boostrelease ;
+explicit boostrelease ;
diff --git a/doc/container.qbk b/doc/container.qbk
new file mode 100644
index 0000000..4f8ea7f
--- /dev/null
+++ b/doc/container.qbk
@@ -0,0 +1,1558 @@
+[/
+ / Copyright (c) 2009-2018 Ion Gazta\u00F1aga
+ /
+ / 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)
+ /]
+
+[library Boost.Container
+ [quickbook 1.5]
+ [authors [Gaztanaga, Ion]]
+ [copyright 2009-2018 Ion Gaztanaga]
+ [id container]
+ [dirname container]
+ [purpose Containers library]
+ [license
+ 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])
+ ]
+]
+
+[template super[x]'''<superscript>'''[x]'''</superscript>''']
+[template sub[x]'''<subscript>'''[x]'''</subscript>''']
+
+[section:intro Introduction]
+
+[*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?
+
+* Emplacement and move semantics are implemented, including emulation for pre-C++11 compilers.
+* Polymorphic allocators and memory resources, including implementation and emulation for pre-C++17 compilers
+* New advanced features (e.g. recursive containers, configuration options for containers) are present.
+* Containers support stateful allocators and are compatible with [*Boost.Interprocess]
+ (they can be safely placed in shared memory).
+* Users obtain a more uniform performance across all plataforms,
+ including [link container.main_features.scary_iterators SCARY iterators].
+* The library offers new useful containers:
+ * [classref boost::container::flat_map flat_map],
+ [classref boost::container::flat_set flat_set],
+ [classref boost::container::flat_multimap flat_multimap] and
+ [classref boost::container::flat_multiset flat_multiset]: drop-in
+ replacements for standard associative containers but more memory friendly and with faster
+ searches.
+ * [classref boost::container::stable_vector stable_vector]: a std::list and std::vector hybrid
+ container: vector-like random-access iterators and list-like iterator stability in insertions and erasures.
+ * [classref boost::container::static_vector 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.
+ * [classref boost::container::small_vector 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.
+ * [classref boost::container::slist slist]: the classic pre-standard singly linked list implementation
+ offering constant-time `size()`. Note that C++11 `forward_list` has no `size()`.
+
+[section:introduction_building_container Building Boost.Container]
+
+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*:
+
+* [link container.extended_allocators Extended Allocators]
+* Some [link container.cpp_conformance.polymorphic_memory_resources Polymorphic Memory Resources] classes.
+
+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 [@http://www.boost.org/doc/libs/release/more/getting_started/index.html Boost Getting Started]
+instructions, that's already been done for you.
+
+[endsect]
+
+[section:tested_compilers Tested compilers]
+
+[*Boost.Container] requires a decent C++98 compatibility. Some compilers known to work are:
+
+* Visual C++ >= 7.1.
+* GCC >= 4.1.
+* Intel C++ >= 9.0
+
+[endsect]
+
+[endsect]
+
+[section:main_features Main features]
+
+[section:move_emplace Efficient insertion]
+
+Move semantics and placement insertion are two features brought by C++11 containers
+that can have a very positive impact in your C++ applications. Boost.Container implements
+both techniques both for C++11 and C++03 compilers.
+
+[section:move_containers Move-aware containers]
+
+All containers offered by [*Boost.Container] can store movable-only types
+and actual requirements for `value_type` depend on each container operations.
+Following C++11 requirements even for C++03 compilers, many operations now require
+movable or default constructible types instead of just copy constructible types.
+
+Containers themselves are also movable, with no-throw guarantee if allocator
+or predicate (if present) copy operations are no-throw. This allows
+high performance operations when transferring data between vectors.
+Let's see an example:
+
+[import ../example/doc_move_containers.cpp]
+[doc_move_containers]
+
+[endsect]
+
+[section:emplace Emplace: Placement insertion]
+
+All containers offered by [*Boost.Container] implement placement insertion,
+which means that objects can be built directly into the container from user arguments
+without creating any temporary object. For compilers without variadic templates support
+placement insertion is emulated up to a finite (10) number of arguments.
+
+Expensive to move types are perfect candidates emplace functions and in case of node containers
+([classref boost::container::list list], [classref boost::container::set set], ...)
+emplace allows storing non-movable and non-copyable types in containers! Let's
+see an example:
+
+[import ../example/doc_emplace.cpp]
+[doc_emplace]
+
+[endsect]
+
+[endsect]
+
+
+[section:containers_of_incomplete_types Containers of Incomplete Types]
+
+Incomplete types allow
+[@http://en.wikipedia.org/wiki/Type_erasure [*type erasure ]] and
+[@http://en.wikipedia.org/wiki/Recursive_data_type [*recursive data types]], and
+C and C++ programmers have been using it for years to build complex data structures, like
+tree structures where a node may have an arbitrary number of children.
+
+What about standard containers? Containers of incomplete types have been under discussion for a long time,
+as explained in Matt Austern's great article ([@http://drdobbs.com/184403814 [*The Standard Librarian: Containers of Incomplete Types]]):
+
+["['Unlike most of my columns, this one is about something you can't do with the C++ Standard library:
+put incomplete types in one of the standard containers. This column explains why you might want to
+do this, why the standardization committee banned it even though they knew it was useful, and what
+you might be able to do to get around the restriction.]]
+
+["['In 1997, shortly before the C++ Standard was completed, the standardization committee received a
+query: Is it possible to create standard containers with incomplete types? It took a while for the
+committee to understand the question. What would such a thing even mean, and why on earth would you
+ever want to do it? The committee eventually worked it out and came up with an answer to the question.
+(Just so you don't have to skip ahead to the end, the answer is "no.") But the question is much more
+interesting than the answer: it points to a useful, and insufficiently discussed, programming technique.
+The standard library doesn't directly support that technique, but the two can be made to coexist.]]
+
+["['In a future revision of C++, it might make sense to relax the restriction on instantiating
+standard library templates with incomplete types. Clearly, the general prohibition should stay
+in place - instantiating templates with incomplete types is a delicate business, and there are
+too many classes in the standard library where it would make no sense. But perhaps it should be
+relaxed on a case-by-case basis, and `vector` looks like a good candidate for such special-case
+treatment: it's the one standard container class where there are good reasons to instantiate
+it with an incomplete type and where Standard Library implementors want to make it work. As of
+today, in fact, implementors would have to go out of their way to prohibit it!]]
+
+C++11 standard is also cautious about incomplete types and STL: ["['17.6.4.8 Other functions (...) 2.
+the effects are undefined in the following cases: (...) In particular - if an incomplete type (3.9)
+is used as a template argument when instantiating a template component,
+unless specifically allowed for that component]].
+
+Finally C++17 added support for incomplete types in `std::vector`, `std::list` and `std::forward_list`
+(see [@https://wg21.link/n4569 ['N4569: Minimal incomplete type support for standard containers, revision 4]]
+for details), but no other containers like `std::set/map/unordered_set/unordered_map`,
+
+Fortunately all [*Boost.Container] containers except
+[classref boost::container::static_vector static_vector] and
+[classref boost::container::small_vector small_vector] and
+[classref boost::container::basic_string basic_string] are designed to support incomplete types.
+[classref boost::container::static_vector static_vector] and
+[classref boost::container::small_vector small_vector] are special because
+they statically allocates memory for `value_type` and this requires complete types.
+[classref boost::container::basic_string basic_string] implements Small String Optimization which
+also requires complete types.
+
+[*Boost.Container] containers supporting incomplete types also support instantiating iterators to
+those incomplete elements.
+
+[section:recursive_containers Recursive containers]
+
+Most [*Boost.Container] containers can be used to define recursive containers:
+
+[import ../example/doc_recursive_containers.cpp]
+[doc_recursive_containers]
+
+[endsect]
+
+[section:type_erasure Type Erasure]
+
+Containers of incomplete types are useful to break header file dependencies and improve
+compilation types. With Boost.Container, you can write a header file defining a class
+with containers of incomplete types as data members, if you carefully put all the
+implementation details that require knowing the size of the `value_type` in your
+implementation file:
+
+[import ../example/doc_type_erasure.cpp]
+
+In this header file we define a class (`MyClassHolder)` that holds a `vector` of an
+incomplete type (`MyClass`) that it's only forward declared.
+
+[doc_type_erasure_MyClassHolder_h]
+
+Then we can define `MyClass` in its own header file.
+
+[doc_type_erasure_MyClass_h]
+
+And include it only in the implementation file of `MyClassHolder`
+
+[doc_type_erasure_MyClassHolder_cpp]
+
+Finally, we can just compile, link, and run!
+
+[doc_type_erasure_main_cpp]
+
+[endsect]
+
+[endsect]
+
+[section:scary_iterators SCARY iterators]
+
+The paper N2913, titled [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2913.pdf
+SCARY Iterator Assignment and Initialization], proposed a requirement that a standard container's
+iterator types have no dependency on any type argument apart from the container's `value_type`,
+`difference_type`, `pointer type`, and `const_pointer` type. In particular, according to the proposal,
+the types of a standard container's iterators should not depend on the container's `key_compare`,
+`hasher`, `key_equal`, or `allocator` types.
+
+That paper demonstrated that SCARY operations were crucial to the performant implementation of common
+design patterns using STL components. It showed that implementations that support SCARY operations reduce
+object code bloat by eliminating redundant specializations of iterator and algorithm templates.
+
+[*Boost.Container] containers implement SCARY iterators so the iterator type of a container is only dependent
+on the `allocator_traits<allocator_type>::pointer` type (the pointer type of the `value_type` to be inserted
+in the container). Reference types and all other typedefs are deduced from the pointer type using the
+C++11 `pointer_traits` utility. This leads to lower code bloat in algorithms and classes templated on
+iterators.
+
+[endsect]
+
+[section:other_features Other features]
+
+* Default constructors don't allocate memory which improves performance and
+ usually implies a no-throw guarantee (if predicate's or allocator's default constructor doesn't throw).
+
+* Small string optimization for [classref boost::container::basic_string basic_string],
+ with an internal buffer of 11/23 bytes (32/64 bit systems)
+ [*without] increasing the usual `sizeof` of the string (3 words).
+
+* `[multi]set/map` containers are size optimized embedding the color bit of the red-black tree nodes
+ in the parent pointer.
+
+* `[multi]set/map` containers use no recursive functions so stack problems are avoided.
+
+[endsect]
+
+[endsect]
+
+[section:exception_handling Boost.Container and C++ exceptions]
+
+In some environments, such as game development or embedded systems, C++ exceptions are disabled or a customized error handling is needed.
+According to document [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html N2271 EASTL -- Electronic Arts Standard Template Library]
+exceptions can be disabled for several reasons:
+
+* ["['Exception handling incurs some kind of cost in all compiler implementations, including those that avoid
+ the cost during normal execution. However, in some cases this cost may arguably offset the cost of the code that it is replacing.]]
+* ["['Exception handling is often agreed to be a superior solution for handling a large range of function return values. However,
+ avoiding the creation of functions that need large ranges of return values is superior to using exception handling to handle such values.]]
+* ["['Using exception handling correctly can be difficult in the case of complex software.]]
+* ["['The execution of throw and catch can be significantly expensive with some implementations.]]
+* ["['Exception handling violates the don't-pay-for-what-you-don't-use design of C++, as it incurs overhead in any non-leaf function that
+ has destructible stack objects regardless of whether they use exception handling.]]
+* ["['The approach that game software usually takes is to avoid the need for exception handling where possible; avoid the possibility
+ of circumstances that may lead to exceptions. For example, verify up front that there is enough memory for a subsystem to do its job
+ instead of trying to deal with the problem via exception handling or any other means after it occurs.]]
+* ["['However, some game libraries may nevertheless benefit from the use of exception handling. It's best, however,
+ if such libraries keep the exception handling internal lest they force their usage of exception handling on the rest of the application.]]
+
+In order to support environments without C++ exception support or environments with special error handling needs,
+[*Boost.Container] changes error signalling behaviour when `BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS` or `BOOST_NO_EXCEPTIONS`
+is defined. The former shall be defined by the user and the latter can be either defined by the user or implicitly defined by [*Boost.Confg]
+when the compiler has been invoked with the appropriate flag (like `-fno-exceptions` in GCC).
+
+When dealing with user-defined classes, (e.g. when constructing user-defined classes):
+
+* If `BOOST_NO_EXCEPTIONS` is defined, the library avoids using `try`/`catch`/`throw` statements. The class writer must handle and
+ propagate error situations internally as no error will be propagated through [*Boost.Container].
+* If `BOOST_NO_EXCEPTIONS` is *not* defined, the library propagates exceptions offering the exception guarantees detailed in the documentation.
+
+When the library needs to throw an exception (such as `out_of_range` when an incorrect index is used in `vector::at`), the library calls
+a throw-callback declared in [headerref boost/container/throw_exception.hpp]:
+
+* If `BOOST_CONTAINER_USER_DEFINED_THROW_CALLBACKS` is defined, then the programmer must provide its own definition for all
+ `throw_xxx` functions. Those functions can't return, they must throw an exception or call `std::exit` or `std::abort`.
+* Else if `BOOST_NO_EXCEPTIONS` is defined, a `BOOST_ASSERT_MSG` assertion is triggered
+ (see [@http://www.boost.org/libs/utility/assert.html Boost.Assert] for more information).
+ If this assertion returns, then `std::abort` is called.
+* Else, an appropriate standard library exception is thrown (like `std::out_of_range`).
+
+[endsect]
+
+[section:non_standard_containers Non-standard containers]
+
+[section:stable_vector ['stable_vector]]
+
+This useful, fully STL-compliant stable container [@http://bannalia.blogspot.com/2008/09/introducing-stablevector.html designed by Joaqu\u00EDn M. L\u00F3pez Mu\u00F1oz]
+is an hybrid between `vector` and `list`, providing most of
+the features of `vector` except [@http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#69 element contiguity].
+
+Extremely convenient as they are, `vector`s have a limitation that many novice C++ programmers frequently stumble upon:
+iterators and references to an element of an `vector` are invalidated when a preceding element is erased or when the
+vector expands and needs to migrate its internal storage to a wider memory region (i.e. when the required size exceeds
+the vector's capacity). We say then that `vector`s are unstable: by contrast, stable containers are those for which
+references and iterators to a given element remain valid as long as the element is not erased: examples of stable containers
+within the C++ standard library are `list` and the standard associative containers (`set`, `map`, etc.).
+
+Sometimes stability is too precious a feature to live without, but one particular property of `vector`s, element contiguity,
+makes it impossible to add stability to this container. So, provided we sacrifice element contiguity, how much
+can a stable design approach the behavior of `vector` (random access iterators, amortized constant time end
+insertion/deletion, minimal memory overhead, etc.)?
+The following image describes the layout of a possible data structure upon which to base the design of a stable vector:
+
+[$../../libs/container/doc/images/stable_vector.png [width 50%] [align center] ]
+
+Each element is stored in its own separate node. All the nodes are referenced from a contiguous array of pointers, but
+also every node contains an "up" pointer referring back to the associated array cell. This up pointer is the key element
+to implementing stability and random accessibility:
+
+Iterators point to the nodes rather than to the pointer array. This ensures stability, as it is only the pointer array
+that needs to be shifted or relocated upon insertion or deletion. Random access operations can be implemented by using
+the pointer array as a convenient intermediate zone. For instance, if the iterator it holds a node pointer `it.p` and we
+want to advance it by n positions, we simply do:
+
+[c++]
+
+ it.p = *(it.p->up+n);
+
+That is, we go "up" to the pointer array, add n there and then go "down" to the resulting node.
+
+[*General properties]. `stable_vector` satisfies all the requirements of a container, a reversible container and a sequence
+and provides all the optional operations present in vector. Like vector, iterators are random access. `stable_vector`
+does not provide element contiguity; in exchange for this absence, the container is stable, i.e. references and iterators
+to an element of a `stable_vector` remain valid as long as the element is not erased, and an iterator that has been
+assigned the return value of end() always remain valid until the destruction of the associated `stable_vector`.
+
+[*Operation complexity]. The big-O complexities of `stable_vector` operations match exactly those of vector. In general,
+insertion/deletion is constant time at the end of the sequence and linear elsewhere. Unlike vector, `stable_vector`
+does not internally perform any value_type destruction, copy/move construction/assignment operations other than those exactly
+corresponding to the insertion of new elements or deletion of stored elements, which can sometimes compensate in terms of
+performance for the extra burden of doing more pointer manipulation and an additional allocation per element.
+
+[*Exception safety]. (according to [@http://www.boost.org/community/exception_safety.html Abrahams' terminology])
+As `stable_vector` does not internally copy/move elements around, some
+operations provide stronger exception safety guarantees than in vector:
+
+[table:stable_vector_req Exception safety
+ [[operation] [exception safety for `vector<T>`] [exception safety for `stable_vector<T>`]]
+ [[insert] [strong unless copy/move construction/assignment of `T` throw (basic)] [strong]]
+ [[erase] [no-throw unless copy/move construction/assignment of `T` throw (basic)] [no-throw]]
+]
+
+[*Memory overhead]. The C++ standard does not specifiy requirements on memory consumption, but virtually any implementation
+of `vector` has the same behavior wih respect to memory usage: the memory allocated by a `vector` v with n elements of type T
+is
+
+m[sub v] = c\u2219e,
+
+where c is `v.capacity()` and e is `sizeof(T)`. c can be as low as n if the user has explicitly reserved the exact capacity
+required; otherwise, the average value c for a growing `vector` oscillates between 1.25\u2219n and 1.5\u2219n for typical resizing
+policies. For `stable_vector`, the memory usage is
+
+m[sub sv] = (c + 1)p + (n + 1)(e + p),
+
+where p is the size of a pointer. We have c + 1 and n + 1 rather than c and n because a dummy node is needed at the end of
+the sequence. If we call f the capacity to size ratio c/n and assume that n is large enough, we have that
+
+m[sub sv]/m[sub v] \u2243 (fp + e + p)/fe.
+
+So, `stable_vector` uses less memory than `vector` only when e > p and the capacity to size ratio exceeds a given threshold:
+
+m[sub sv] < m[sub v] <-> f > (e + p)/(e - p). (provided e > p)
+
+This threshold approaches typical values of f below 1.5 when e > 5p; in a 32-bit architecture, when e > 20 bytes.
+
+[*Summary]. `stable_vector` is a drop-in replacement for `vector` providing stability of references and iterators, in exchange
+for missing element contiguity and also some performance and memory overhead. When the element objects are expensive to
+move around, the performance overhead can turn into a net performance gain for `stable_vector` if many middle insertions
+or deletions are performed or if resizing is very frequent. Similarly, if the elements are large there are situations when
+the memory used by `stable_vector` can actually be less than required by vector.
+
+['Note: Text and explanations taken from [@http://bannalia.blogspot.com/2008/09/introducing-stablevector.html Joaqu\u00EDn's blog]]
+
+[endsect]
+
+[section:flat_xxx ['flat_(multi)map/set] associative containers]
+
+Using sorted vectors instead of tree-based associative containers is a well-known technique in
+C++ world. Matt Austern's classic article
+[@http://lafstern.org/matt/col1.pdf Why You Shouldn't Use set, and What You Should Use Instead]
+(C++ Report 12:4, April 2000) was enlightening:
+
+["['Red-black trees aren't the only way to organize data that permits lookup in logarithmic time. One of the basic
+algorithms of computer science is binary search, which works by successively dividing a range in half. Binary
+search is log N and it doesn't require any fancy data structures, just a sorted collection of elements.
+(...) You can use whatever data structure is convenient, so long as it provides STL iterator;
+usually it's easiest to use a C array, or a vector.]]
+
+["['Both std::lower_bound and set::find take time proportional to log N, but the constants of proportionality
+are very different. Using g++ (...) it takes X seconds to perform a million lookups in a
+sorted vector<double> of a million elements, and almost twice as long (...) using a set. Moreover,
+the set uses almost three times as much memory (48 million bytes) as the vector (16.8 million).]]
+
+["['Using a sorted vector instead of a set gives you faster lookup and much faster iteration,
+but at the cost of slower insertion. Insertion into a set, using set::insert, is proportional
+to log N, but insertion into a sorted vector, (...)
+, is proportional to N. Whenever you insert something into a vector,
+vector::insert has to make room by shifting all of the elements that follow it. On average, if you're equally
+likely to insert a new element anywhere, you'll be shifting N/2 elements.]]
+
+["['It may sometimes be convenient to bundle all of this together into a small container adaptor.
+This class does not satisfy the requirements of a Standard Associative Container, since the complexity of insert is
+O(N) rather than O(log N), but otherwise it is almost a drop-in replacement for set.]]
+
+Following Matt Austern's indications, Andrei Alexandrescu's
+[@http://www.bestwebbuys.com/Modern-C-Design-Generic-Programming-and-Design-Patterns-Applied-ISBN-9780201704310?isrc=-rd Modern C++ Design]
+showed `AssocVector`, a `std::map` drop-in
+replacement designed in his [@http://loki-lib.sourceforge.net/ Loki] library:
+
+["['It seems as if we're better off with a sorted vector. The disadvantages of a sorted
+vector are linear-time insertions and linear-time deletions (...). In exchange, a vector
+offers about twice the lookup speed and a much smaller working set (...).
+Loki saves the trouble of maintaining a sorted vector by hand by defining an AssocVector class
+template. AssocVector is a drop-in replacement for std::map (it supports the same set of member
+functions), implemented on top of std::vector. AssocVector differs from a map in the behavior of
+its erase functions (AssocVector::erase invalidates all iterators into the object) and in the
+complexity guarantees of insert and erase (linear as opposed to constant). ]]
+
+[*Boost.Container] `flat_[multi]map/set` containers are ordered, vector-like container based, associative
+containers following Austern's and Alexandrescu's guidelines. These ordered vector containers have also
+benefited with the addition of `move semantics` to C++11, speeding up insertion and
+erasure times considerably. Flat associative containers have the following attributes:
+
+* Faster lookup than standard associative containers
+* Much faster iteration than standard associative containers.
+ Random-access iterators instead of bidirectional iterators.
+* Less memory consumption for small objects (and for big objects if `shrink_to_fit` is used)
+* Improved cache performance (data is stored in contiguous memory)
+* Non-stable iterators (iterators are invalidated when inserting and erasing elements)
+* Non-copyable and non-movable values types can't be stored
+* Weaker exception safety than standard associative containers
+(copy/move constructors can throw when shifting values in erasures and insertions)
+* Slower insertion and erasure than standard associative containers (specially for non-movable types)
+
+[endsect]
+
+[section:slist ['slist]]
+
+When the standard template library was designed, it contained a singly linked list called `slist`.
+Unfortunately, this container was not standardized and remained as an extension for many standard
+library implementations until C++11 introduced `forward_list`, which is a bit different from the
+the original SGI `slist`. According to [@http://www.sgi.com/tech/stl/Slist.html SGI STL documentation]:
+
+["['An `slist` is a singly linked list: a list where each element is linked to the next element, but
+not to the previous element. That is, it is a Sequence that supports forward but not backward traversal,
+and (amortized) constant time insertion and removal of elements. Slists, like lists, have the important
+property that insertion and splicing do not invalidate iterators to list elements, and that even removal
+invalidates only the iterators that point to the elements that are removed. The ordering of iterators
+may be changed (that is, slist<T>::iterator might have a different predecessor or successor after a list
+operation than it did before), but the iterators themselves will not be invalidated or made to point to
+different elements unless that invalidation or mutation is explicit.]]
+
+["['The main difference between `slist` and list is that list's iterators are bidirectional iterators,
+while slist's iterators are forward iterators. This means that `slist` is less versatile than list;
+frequently, however, bidirectional iterators are unnecessary. You should usually use `slist` unless
+you actually need the extra functionality of list, because singly linked lists are smaller and faster
+than double linked lists.]]
+
+["['Important performance note: like every other Sequence, `slist` defines the member functions insert and erase.
+Using these member functions carelessly, however, can result in disastrously slow programs. The problem is that
+insert's first argument is an iterator pos, and that it inserts the new element(s) before pos. This means that
+insert must find the iterator just before pos; this is a constant-time operation for list, since list has
+bidirectional iterators, but for `slist` it must find that iterator by traversing the list from the beginning
+up to pos. In other words: insert and erase are slow operations anywhere but near the beginning of the slist.]]
+
+["['Slist provides the member functions insert_after and erase_after, which are constant time operations: you should
+always use insert_after and erase_after whenever possible. If you find that insert_after and erase_after aren't
+adequate for your needs, and that you often need to use insert and erase in the middle of the list, then you
+should probably use list instead of slist.]]
+
+[*Boost.Container] updates the classic `slist` container with C++11 features like move semantics and placement
+insertion and implements it a bit differently than the standard C++ `forward_list`. `forward_list` has no `size()`
+method, so it's been designed to allow (or in practice, encourage) implementations without tracking list size
+with every insertion/erasure, allowing constant-time
+`splice_after(iterator, forward_list &, iterator, iterator)`-based list merging. On the other hand `slist` offers
+constant-time `size()` for those that don't care about linear-time `splice_after(iterator, slist &, iterator, iterator)`
+`size()` and offers an additional `splice_after(iterator, slist &, iterator, iterator, size_type)` method that
+can speed up `slist` merging when the programmer already knows the size. `slist` and `forward_list` are therefore
+complementary.
+
+[endsect]
+
+[section:static_vector ['static_vector]]
+
+`static_vector` is an hybrid between `vector` and `array`: like `vector`, it's a sequence container
+with contiguous storage that can change in size, along with the static allocation, low overhead,
+and fixed capacity of `array`. `static_vector` is based on Adam Wulkiewicz and Andrew Hundt's
+high-performance [@https://svn.boost.org/svn/boost/sandbox/varray/doc/html/index.html varray]
+class.
+
+The number of elements in a `static_vector` may vary dynamically up to a fixed capacity
+because elements are stored within the object itself similarly to an array. However, objects are
+initialized as they are inserted into `static_vector` unlike C arrays or `std::array` which must construct
+all elements on instantiation. The behavior of `static_vector` enables the use of statically allocated
+elements in cases with complex object lifetime requirements that would otherwise not be trivially
+possible. Some other properties:
+
+* Random access to elements
+* Constant time insertion and removal of elements at the end
+* Linear time insertion and removal of elements at the beginning or in the middle.
+
+`static_vector` is well suited for use in a buffer, the internal implementation of other
+classes, or use cases where there is a fixed limit to the number of elements that must be stored.
+Embedded and realtime applications where allocation either may not be available or acceptable
+are a particular case where `static_vector` can be beneficial.
+
+[endsect]
+
+[section:small_vector ['small_vector]]
+
+`small_vector` is a vector-like container optimized for the case when it contains few elements.
+It contains some preallocated elements in-place, which allows it to avoid the use of dynamic storage allocation
+when the actual number of elements is below that preallocated threshold. `small_vector` is inspired by
+[@http://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h LLVM's `SmallVector`] container.
+Unlike `static_vector`, `small_vector`'s capacity can grow beyond the initial preallocated capacity.
+
+`small_vector<T, N, Allocator>` is convertible to `small_vector_base<T, Allocator>`, a type that is independent
+from the preallocated element count, allowing client code that does not need to be templated on that N argument.
+`small_vector` inherits all `vector`'s member functions so it supports all standard features like emplacement,
+stateful allocators, etc.
+
+[endsect]
+
+[endsect]
+
+[section:extended_functionality Extended functionality: Basic extensions]
+
+[section:default_initialialization Default initialization for vector-like containers]
+
+STL and most other containers value initialize new elements in common operations like
+`vector::resize(size_type n)` or `explicit vector::vector(size_type n)`.
+
+In some performance-sensitive environments, where vectors are used as a replacement for
+variable-size buffers for file or network operations,
+[@http://en.cppreference.com/w/cpp/language/value_initialization value initialization]
+is a cost that is not negligible as elements are going to be overwritten by an external source
+shortly after new elements are added to the container.
+
+[*Boost.Container] offers two new members for `vector`, `static_vector` and `stable_vector`:
+`explicit container::container(size_type n, default_init_t)` and
+`container::resize(size_type n, default_init_t)`, where new elements are constructed
+using [@http://en.cppreference.com/w/cpp/language/default_initialization default initialization].
+
+[endsect]
+
+[section:ordered_range_insertion Ordered range insertion for associative containers (['ordered_unique_range], ['ordered_range]) ]
+
+When filling associative containers big performance gains can be achieved if the input range to be inserted
+is guaranteed by the user to be ordered according to the predicate. This can happen when inserting values from a `set` to
+a `multiset` or between different associative container families (`[multi]set/map` vs. `flat_[multi]set/map`).
+
+[*Boost.Container] has some overloads for constructors and insertions taking an `ordered_unique_range_t` or
+an `ordered_range_t` tag parameters as the first argument. When an `ordered_unique_range_t` overload is used, the
+user notifies the container that the input range is ordered according to the container predicate and has no
+duplicates. When an `ordered_range_t` overload is used, the
+user notifies the container that the input range is ordered according to the container predicate but it might
+have duplicates. With this information, the container can avoid multiple predicate calls and improve insertion
+times.
+
+[endsect]
+
+[section:constant_time_range_splice Constant-time range splice for `(s)list`]
+
+In the first C++ standard `list::size()` was not required to be constant-time,
+and that caused some controversy in the C++ community. Quoting Howard Hinnant's
+[@http://howardhinnant.github.io/On_list_size.html ['On List Size]] paper:
+
+[: ['There is a considerable debate on whether `std::list<T>::size()` should be O(1) or O(N).
+The usual argument notes that it is a tradeoff with:]
+
+`splice(iterator position, list& x, iterator first, iterator last);`
+
+['If size() is O(1) and this != &x, then this method must perform a linear operation so that it
+can adjust the size member in each list]]
+
+C++11 definitely required `size()` to be O(1), so range splice became O(N). However,
+Howard Hinnant's paper proposed a new `splice` overload so that even O(1) `list:size()`
+implementations could achieve O(1) range splice when the range size was known to the caller:
+
+[: `void splice(iterator position, list& x, iterator first, iterator last, size_type n);`
+
+ [*Effects]: Inserts elements in the range [first, last) before position and removes the elements from x.
+
+ [*Requires]: [first, last) is a valid range in x. The result is undefined if position is an iterator in the range [first, last). Invalidates only the iterators and references to the spliced elements. n == distance(first, last).
+
+ [*Throws]: Nothing.
+
+ [*Complexity]: Constant time.
+]
+
+This new splice signature allows the client to pass the distance of the input range in.
+This information is often available at the call site. If it is passed in,
+then the operation is constant time, even with an O(1) size.
+
+[*Boost.Container] implements this overload for `list` and a modified version of it for `slist`
+(as `slist::size()` is also `O(1)`).
+
+[endsect]
+
+[endsect]
+
+[section:configurable_containers Extended functionality: Configurable containers]
+
+[section:configurable_tree_based_associative_containers Configurable tree-based associative ordered containers]
+
+[classref boost::container::set set], [classref boost::container::multiset multiset],
+[classref boost::container::map map] and [classref boost::container::multimap multimap] associative containers
+are implemented as binary search trees which offer the needed complexity and stability guarantees required by the
+C++ standard for associative containers.
+
+[*Boost.Container] offers the possibility to configure at compile time some parameters of the binary search tree
+implementation. This configuration is passed as the last template parameter and defined using the utility class
+[classref boost::container::tree_assoc_options tree_assoc_options]. The following parameters can be configured:
+
+* The underlying [*tree implementation] type ([classref boost::container::tree_type tree_type]).
+ By default these containers use a red-black tree but the user can use other tree types:
+ * [@http://en.wikipedia.org/wiki/Red%E2%80%93black_tree Red-Black Tree]
+ * [@http://en.wikipedia.org/wiki/Avl_trees AVL tree]
+ * [@http://en.wikipedia.org/wiki/Scapegoat_tree Scapegoat tree]. In this case Insertion and Deletion
+ are amortized O(log n) instead of O(log n).
+ * [@http://en.wikipedia.org/wiki/Splay_tree Splay tree]. In this case Searches, Insertions and Deletions
+ are amortized O(log n) instead of O(log n).
+
+* Whether the [*size saving] mechanisms are used to implement the tree nodes
+ ([classref boost::container::optimize_size optimize_size]). By default this option is activated and is only
+ meaningful to red-black and avl trees (in other cases, this option will be ignored).
+ This option will try to put rebalancing metadata inside the "parent" pointer of the node if the pointer
+ type has enough alignment. Usually, due to alignment issues, the metadata uses the size of a pointer yielding
+ to four pointer size overhead per node, whereas activating this option usually leads to 3 pointer size overhead.
+ Although some mask operations must be performed to extract
+ data from this special "parent" pointer, in several systems this option also improves performance due to the
+ improved cache usage produced by the node size reduction.
+
+See the following example to see how [classref boost::container::tree_assoc_options tree_assoc_options] can be
+used to customize these containers:
+
+[import ../example/doc_custom_tree.cpp]
+[doc_custom_tree]
+
+[endsect]
+
+[section:configurable_vectors Configurable vectors]
+
+[*Boost.Container] offers the possibility to configure at compile time some parameters of
+[classref boost::container::vector vector] implementation. This configuration is passed as
+the last template parameter and defined using the utility class
+[classref boost::container::vector_options vector_options]. The following parameters can be configured:
+
+* [classref boost::container::growth_factor growth_factor]: the growth policy of the vector.
+ The rate at which the capacity of a vector grows is implementation dependent and
+ implementations choose exponential growth in order to meet the amortized constant time requirement for push_back.
+ A higher growth factor will make it faster as it will require less data movement, but it will have a greater memory
+ impact (on average, more memory will be unused). A user can provide it's own implementation and some predefined
+ policies are available: [classref boost::container::growth_factor_50 growth_factor_50],
+ [classref boost::container::growth_factor_60 growth_factor_60] and
+ [classref boost::container::growth_factor_50 growth_factor_100].
+
+* [classref boost::container::stored_size stored_size]: the type that will be used to store size-related
+ parameters inside of the vector. Sometimes, when the maximum capacity to be used is much less than the
+ theoretical maximum that a vector can hold, it's interesting to use smaller unsigned integer types to represent
+ `size()` and `capacity()` inside vector, so that the size of an empty vector is minimized and cache
+ performance might be improved. See [classref boost::container::stored_size stored_size] for more details.
+
+See the following example to see how [classref boost::container::vector_options vector_options] can be
+used to customize `vector` container:
+
+[import ../example/doc_custom_vector.cpp]
+[doc_custom_vector]
+
+[endsect]
+
+[endsect]
+
+[section:extended_allocators Extended functionality: Extended allocators]
+
+Many C++ programmers have ever wondered where does good old realloc fit in C++. And that's a good question.
+Could we improve [classref boost::container::vector vector] performance using memory expansion mechanisms
+to avoid too many copies? But [classref boost::container::vector vector] is not the only container that
+could benefit from an improved allocator interface: we could take advantage of the insertion of multiple
+elements in [classref boost::container::list list] using a burst allocation mechanism that could amortize
+costs (mutex locks, free memory searches...) that can't be amortized when using single node allocation
+strategies.
+
+These improvements require extending the STL allocator interface and use make use of a new
+general purpose allocator since new and delete don't offer expansion and burst capabilities.
+
+* [*Boost.Container] containers support an extended allocator interface based on an evolution of proposals
+[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1953.html N1953: Upgrading the Interface of Allocators using API Versioning],
+[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2045.html N2045: Improving STL allocators]
+and the article
+[@http://www.drivehq.com/web/igaztanaga/allocplus/ Applying classic memory allocation strategies to C++ containers].
+The extended allocator interface is implemented by [classref boost::container::allocator allocator],
+[classref boost::container::adaptive_pool adaptive_pool] and [classref boost::container::node_allocator node_allocator]
+classes.
+
+* Extended allocators use a modified [@http://g.oswego.edu/dl/html/malloc.html Doug Lea Malloc (DLMalloc)] low-level
+allocator and offers an C API to implement memory expansion and burst allocations. DLmalloc is known to be very size
+and speed efficient, and this allocator is used as the basis of many malloc implementations, including multithreaded
+allocators built above DLmalloc (See [@http://www.malloc.de/en/ ptmalloc2, ptmalloc3] or
+[@http://www.nedprod.com/programs/portable/nedmalloc/ nedmalloc]). This low-level allocator is implemented as
+a separately compiled library and the following extended allocators depend on the library:
+
+* [classref boost::container::allocator allocator]: This extended allocator offers expansion, shrink-in place
+ and burst allocation capabilities implemented as a thin wrapper around the modified DLMalloc.
+ It can be used with all containers and it should be the default choice when the programmer wants to use
+ extended allocator capabilities.
+
+* [classref boost::container::node_allocator node_allocator]: It's a
+ [@http://www.boost.org/doc/libs/1_55_0/libs/pool/doc/html/boost_pool/pool/pooling.html#boost_pool.pool.pooling.simple Simple Segregated Storage]
+ allocator, similar to [*Boost.Pool] that takes advantage of the modified DLMalloc burst interface. It does not return
+ memory to the DLMalloc allocator (and thus, to the system), unless explicitly requested. It does offer a very small
+ memory overhead so it's suitable for node containers ([boost::container::list list], [boost::container::slist slist]
+ [boost::container::set set]...) that allocate very small `value_type`s and it offers improved node allocation times
+ for single node allocations with respecto to [classref boost::container::allocator allocator].
+
+* [classref boost::container::adaptive_pool adaptive_pool]: It's a low-overhead node allocator that can return memory
+ to the system. The overhead can be very low (< 5% for small nodes) and it's nearly as fast as [classref boost::container::node_allocator node_allocator].
+ It's also suitable for node containers.
+
+Use them simply specifying the new allocator in the corresponding template argument of your favourite container:
+
+[import ../example/doc_extended_allocators.cpp]
+[doc_extended_allocators]
+
+[endsect]
+
+[section:cpp_conformance C++11/C++14/C++17 Conformance]
+
+[*Boost.Container] aims for full C++11 conformance except reasoned deviations,
+backporting as much as possible for C++03. Obviously, this conformance is a work
+in progress so this section explains what C++11/C++14/C++17 features are implemented and which
+of them have been backported to earlier standard conformig compilers.
+
+[section:move_emplace Move and Emplace]
+
+For compilers with rvalue references and for those C++03 types that use
+[@http://www.boost.org/libs/move Boost.Move] rvalue reference emulation
+[*Boost.Container] supports all C++11 features related to move semantics: containers
+are movable, requirements for `value_type` are those specified for C++11 containers.
+
+For compilers with variadic templates, [*Boost.Container] supports placement insertion
+(`emplace`, ...) functions from C++11. For those compilers without variadic templates
+support [*Boost.Container] uses the preprocessor to create a set of overloads up to
+a finite number of parameters.
+
+[endsect]
+
+[section:alloc_traits_move_traits Stateful allocators]
+
+C++03 was not stateful-allocator friendly. For compactness of container objects and for
+simplicity, it did not require containers to support allocators with state: Allocator objects
+need not be stored in container objects. It was not possible to store an allocator with state,
+say an allocator that holds a pointer to an arena from which to allocate. C++03 allowed implementors
+to suppose two allocators of the same type always compare equal (that means that memory allocated
+by one allocator object could be deallocated by another instance of the same type) and
+allocators were not swapped when the container was swapped.
+
+C++11 further improves stateful allocator support through
+[@http://en.cppreference.com/w/cpp/memory/allocator_traits `std::allocator_traits`].
+`std::allocator_traits` is the protocol between a container and an allocator, and
+an allocator writer can customize its behaviour (should the container propagate it in
+move constructor, swap, etc.?) following `allocator_traits` requirements. [*Boost.Container]
+not only supports this model with C++11 but also [*backports it to C++03] via
+[classref boost::container::allocator_traits boost::container::allocator_traits] including some
+C++17 changes. This class
+offers some workarounds for C++03 compilers to achieve the same allocator guarantees as
+`std::allocator_traits`.
+
+In [Boost.Container] containers, if possible, a single allocator is hold to construct
+`value_type`s. If the container needs an auxiliary
+allocator (e.g. an array allocator used by `deque` or `stable_vector`), that allocator is also
+stored in the container and initialized from the user-supplied allocator when the
+container is constructed (i.e. it's not constructed on the fly when auxiliary memory is needed).
+
+[endsect]
+
+[section:scoped_allocator Scoped allocators]
+
+C++11 improves stateful allocators with the introduction of
+[@http://en.cppreference.com/w/cpp/memory/scoped_allocator_adaptor `std::scoped_allocator_adaptor`]
+class template. `scoped_allocator_adaptor` is instantiated with one outer allocator and zero or more inner
+allocators.
+
+A scoped allocator is a mechanism to automatically propagate the state of the allocator to the subobjects
+of a container in a controlled way. If instantiated with only one allocator type, the inner allocator
+becomes the `scoped_allocator_adaptor` itself, thus using the same allocator
+resource for the container and every element within the container and, if the elements themselves are
+containers, each of their elements recursively. If instantiated with more than one allocator, the first allocator
+is the outer allocator for use by the container, the second allocator is passed to the constructors of the
+container's elements, and, if the elements themselves are containers, the third allocator is passed to the
+elements' elements, and so on.
+
+[*Boost.Container] implements its own [classref boost::container::scoped_allocator_adaptor scoped_allocator_adaptor]
+class and [*backports this feature also
+to C++03 compilers]. Due to C++03 limitations, in those compilers
+the allocator propagation implemented by `scoped_allocator_adaptor::construct` functions
+will be based on traits ([classref boost::container::constructible_with_allocator_suffix constructible_with_allocator_suffix]
+and [classref boost::container::constructible_with_allocator_prefix constructible_with_allocator_prefix])
+proposed in [@http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2008/n2554.pdf
+N2554: The Scoped Allocator Model (Rev 2) proposal]. In conforming C++11 compilers or compilers supporting SFINAE
+expressions (when `BOOST_NO_SFINAE_EXPR` is NOT defined), traits are ignored and C++11 rules
+(`is_constructible<T, Args..., inner_allocator_type>::value` and
+`is_constructible<T, allocator_arg_t, inner_allocator_type, Args...>::value`)
+will be used to detect if the allocator must be propagated with suffix or prefix allocator arguments.
+
+[endsect]
+
+[section:insertion_hints Insertion hints in associative containers and preserving
+ insertion ordering for elements with equivalent keys]
+
+[@http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#233 LWG Issue #233] corrected a defect
+in C++98 and specified how equivalent keys were to be inserted in associative containers. [*Boost.Container]
+implements the C++11 changes that were specified in [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1780.html N1780
+['Comments on LWG issue 233: Insertion hints in associative containers]]:
+
+* `a_eq.insert(t)`: If a range containing elements equivalent to t exists in a_eq, t is inserted at the end of that range.
+* `a_eq.insert(p,t)`: t is inserted as close as possible to the position just prior to p.
+
+[endsect]
+
+[section:initializer_lists Initializer lists]
+
+[*Boost.Container] supports initialization, assignments and insertions from initializer lists
+in compilers that implement this feature.
+
+[endsect]
+
+[section:null_iterators Null Forward Iterators]
+
+[*Boost.Container] implements
+[@http://www.open-std.org/JTC1/sc22/WG21/docs/papers/2013/n3644.pdf C++14 Null Forward Iterators],
+which means that value-initialized iterators may be compared and compare equal
+to other value-initialized iterators of the same type. Value initialized iterators behave as if they refer
+past the end of the same empty sequence (example taken from N3644):
+
+[c++]
+
+ vector<int> v = { ... };
+ auto ni = vector<int>::iterator();
+ auto nd = vector<double>::iterator();
+ ni == ni; // True.
+ nd != nd; // False.
+ v.begin() == ni; // ??? (likely false in practice).
+ v.end() == ni; // ??? (likely false in practice).
+ ni == nd; // Won't compile.
+
+[endsect]
+
+[section:polymorphic_memory_resources Polymorphic Memory Resources ]
+
+The document
+[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4480.html C++ Extensions for Library Fundamentals (final draft)]
+includes classes that provide allocator type erasure and runtime polymorphism. As Pablo Halpern, the author of the proposal,
+explains in the paper ([@https://isocpp.org/files/papers/N3916.pdf N3916 Polymorphic Memory Resources (r2)]):
+
+["['A significant impediment to effective memory management in C++ has been the
+inability to use allocators in non-generic contexts. In large software systems,
+most of the application program consists of non-generic procedural or
+object-oriented code that is compiled once and linked many times.]]
+
+["['Allocators in C++, however, have historically relied solely on
+compile-time polymorphism, and therefore have not been suitable for use in vocabulary
+types, which are passed through interfaces between separately-compiled modules,
+because the allocator type necessarily affects the type of the object that uses it.
+This proposal builds upon the improvements made to allocators in
+C++11 and describes a set of facilities for runtime polymorphic memory
+resources that interoperate with the existing compile-time polymorphic
+allocators.]]
+
+Most utilities from the Fundamentals TS were merged into C++17, but
+[*Boost.Container] offers them for C++03, C++11 and C++14 compilers.
+
+[*Boost.Container] implements nearly all classes of the proposal under
+the namespace `boost::container::pmr`. There are two groups,
+
+* Header only utilities (these don't require the separately compiled library):
+ * [classref boost::container::pmr::memory_resource memory_resource].
+ * [classref boost::container::pmr::resource_adaptor resource_adaptor].
+
+* Utilities that require the the separately compiled library:
+ * [classref boost::container::pmr::polymorphic_allocator polymorphic_allocator].
+ * [classref boost::container::pmr::monotonic_buffer_resource monotonic_buffer_resource].
+ * [classref boost::container::pmr::unsynchronized_pool_resource unsynchronized_pool_resource].
+ * [classref boost::container::pmr::synchronized_pool_resource synchronized_pool_resource].
+ * Global resource functions: [funcref boost::container::pmr::get_default_resource get_default_resource]/
+ [funcref boost::container::pmr::set_default_resource set_default_resource]/
+ [funcref boost::container::pmr::new_delete_resource new_delete_resource]/
+ [funcref boost::container::pmr::null_memory_resource null_memory_resource]
+ * Aliases for boost containers using the polymorphic allocator
+ (like [classref boost::container::pmr::vector pmr::vector], etc.)
+
+[*Boost.Container]'s polymorphic resource library is usable from C++03 containers,
+and offers some alternative utilities if the required C++11 features of the
+['Library Fundamentals] specification are not available.
+
+[import ../example/doc_pmr.cpp]
+
+Let's review the usage example given in
+[@https://isocpp.org/files/papers/N3916.pdf N3916] and see how it can be implemented
+using [*Boost.Container]: ['Suppose we are processing a series of shopping lists, where a shopping list is a
+container of strings, and storing them in a collection (a list) of shopping lists.
+Each shopping list being processed uses a bounded amount of memory that is needed for
+a short period of time, while the collection of shopping lists uses an unbounded
+amount of memory and will exist for a longer period of time. For efficiency, we can
+use a more time-efficient memory allocator based on a finite buffer for the temporary
+shopping lists.]
+
+Let's see how `ShoppingList` can be defined to support an polymorphic memory resource
+that can allocate memory from different underlying mechanisms. The most important
+details are:
+
+* It should declare that supports an allocator defining an `allocator_type` typedef.
+ This `allocator_type` will be of type [classref boost::container::pmr::memory_resource memory_resource *],
+ which is a base class for polymorphic resources.
+* It must define constructors that take the
+ the allocator as argument. It can be implemented in two ways:
+ * `ShoppingList` has constructors taking
+ [classref boost::container::pmr::memory_resource memory_resource*] as the last argument.
+ * `ShoppingList` has constructors taking
+ [classref boost::container::allocator_arg_t allocator_arg_t] as the first argument
+ and [classref boost::container::pmr::memory_resource memory_resource*] as the second argument.
+
+[*Note:] ['In C++03 compilers, it is required that the programmer specializes as `true`
+[classref boost::container::constructible_with_allocator_suffix constructible_with_allocator_suffix] or
+[classref boost::container::constructible_with_allocator_prefix constructible_with_allocator_prefix]
+as in C++03 there is no way to automatically detect the chosen option at compile time. If
+no specialization is done, [*Boost.Container] assumes the suffix option].
+
+[doc_pmr_ShoppingList_hpp]
+
+['However, this time-efficient allocator is not appropriate for the longer
+lived collection of shopping lists. This example shows how those temporary shopping
+lists, using a time-efficient allocator, can be used to populate the long lived collection
+of shopping lists, using a general purpose allocator, something that would be
+annoyingly difficult without the polymorphic allocators.]
+
+In [*Boost.Container] for the time-efficient allocation we can use
+[classref boost::container::pmr::monotonic_buffer_resource monotonic_buffer_resource],
+providing an external buffer that will be used until it's exhausted. In the default
+configuration, when the buffer is exhausted, the default memory resource will be used
+instead.
+
+[doc_pmr_main_cpp]
+
+['Notice that the shopping lists within `folder` use the default allocator resource
+whereas the shopping list `temporaryShoppingList` uses the short-lived but very fast
+`buf_rsrc`. Despite using different allocators, you can insert
+`temporaryShoppingList` into folder because they have the same `ShoppingList`
+type. Also, while `ShoppingList` uses memory_resource directly,
+[classref boost::container::pmr::list pmr::list],
+[classref boost::container::pmr::vector pmr::vector]
+and [classref boost::container::pmr::string pmr::string] all use
+[classref boost::container::pmr::polymorphic_allocator polymorphic_allocator].]
+
+['The resource passed to the `ShoppingList` constructor is propagated to the vector and
+each string within that `ShoppingList`. Similarly, the resource used to construct
+`folder` is propagated to the constructors of the ShoppingLists that are inserted into
+the list (and to the strings within those `ShoppingLists`). The
+[classref boost::container::pmr::polymorphic_allocator polymorphic_allocator]
+template is designed to be almost interchangeable with a pointer to
+[classref boost::container::pmr::memory_resource memory_resource],
+thus producing a ['bridge] between the template-policy
+style of allocator and the polymorphic-base-class style of allocator.]
+
+This example actually shows how easy is to use [*Boost.Container] to write
+type-erasured allocator-capable classes even in C++03 compilers.
+
+[endsect]
+
+
+[section:forward_list `forward_list<T>`]
+
+[*Boost.Container] does not offer C++11 `forward_list` container yet, but it will be available in future
+versions.
+
+[endsect]
+
+[section:vector_exception_guarantees `vector` vs. `std::vector` exception guarantees]
+
+[classref boost::container::vector vector] does not support the strong exception guarantees
+given by `std::vector` in functions like `insert`, `push_back`, `emplace`, `emplace_back`,
+`resize`, `reserve` or `shrink_to_fit` for either copyable or no-throw moveable classes.
+In C++11 [@http://en.cppreference.com/w/cpp/utility/move_if_noexcept move_if_noexcept] is used
+to maintain C++03 exception safety guarantees combined with C++11 move semantics.
+This strong exception guarantee degrades the insertion performance of copyable and throwing-moveable types,
+degrading moves to copies when such types are inserted in the vector using the aforementioned
+members.
+
+This strong exception guarantee also precludes the possibility of using some type of
+in-place reallocations that can further improve the insertion performance of `vector` See
+[link container.extended_allocators Extended Allocators] to know more
+about these optimizations.
+
+[classref boost::container::vector vector] always uses move constructors/assignments
+to rearrange elements in the vector and uses memory expansion mechanisms if the allocator supports them,
+while offering only basic safety guarantees. It trades off exception guarantees for an improved performance.
+
+[endsect]
+
+[section:container_const_reference_parameters Parameter taken by const reference that can be changed]
+
+Several container operations use a parameter taken by const reference that can be changed during execution of the function.
+[@http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-closed.html#526 LWG Issue 526
+ (['Is it undefined if a function in the standard changes in parameters?])]
+discusses them:
+
+[c++]
+
+ //Given std::vector<int> v
+ v.insert(v.begin(), v[2]);
+ //v[2] can be changed by moving elements of vector
+
+ //Given std::list<int> l:
+ l.remove(*l.begin())
+ //The operation could delete the first element, and then continue trying to access it.
+
+The adopted resolution, NAD (Not A Defect), implies that previous operations must be well-defined. This requires code
+to detect a reference to an inserted element and an additional copy in that case, impacting performance even when
+references to already inserted objects are not used. Note that equivalent functions taking rvalue references or
+iterator ranges require elements not already inserted in the container.
+
+[*Boost.Container] prioritizes performance and has not implemented the NAD resolution:
+in functions that might modify the argument, the library requires references to elements not stored
+in the container. Using references to inserted elements yields to undefined behaviour (although in debug mode, this
+precondition violation could be notified via BOOST_ASSERT).
+
+[endsect]
+
+[section:Vector_bool `vector<bool>` specialization]
+
+`vector<bool>` specialization has been quite problematic, and there have been several
+unsuccessful tries to deprecate or remove it from the standard. [*Boost.Container] does not implement it
+as there is a superior [@http://www.boost.org/libs/dynamic_bitset/ Boost.DynamicBitset]
+solution. For issues with `vector<bool>` see the following papers:
+
+* [@http://howardhinnant.github.io/onvectorbool.html On `vector<bool>`]
+* [@http://www.gotw.ca/publications/N1211.pdf vector<bool>: N1211: More Problems, Better Solutions],
+* [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2160.html N2160: Library Issue 96: Fixing vector<bool>],
+* [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2204.html N2204 A Specification to deprecate vector<bool>].
+
+Quotes:
+
+* ["['But it is a shame that the C++ committee gave this excellent data structure the name vector<bool> and
+ that it gives no guidance nor encouragement on the critical generic algorithms that need to be optimized for this
+ data structure. Consequently, few std::lib implementations go to this trouble.]]
+
+* ["['In 1998, admitting that the committee made a mistake was controversial.
+ Since then Java has had to deprecate such significant portions of their libraries
+ that the idea C++ would be ridiculed for deprecating a single minor template specialization seems quaint.]]
+
+* ["['`vector<bool>` is not a container and `vector<bool>::iterator` is not a random-access iterator
+(or even a forward or bidirectional iterator either, for that matter). This has already broken user code
+in the field in mysterious ways.]]
+
+* ["['`vector<bool>` forces a specific (and potentially bad) optimization choice on all users by enshrining
+it in the standard. The optimization is premature; different users have different requirements. This too
+has already hurt users who have been forced to implement workarounds to disable the 'optimization'
+(e.g., by using a vector<char> and manually casting to/from bool).]]
+
+So `boost::container::vector<bool>::iterator` returns real `bool` references and works as a fully compliant container.
+If you need a memory optimized version of `boost::container::vector<bool>`, please use
+[@http://www.boost.org/libs/dynamic_bitset/ Boost.DynamicBitset].
+
+[endsect]
+
+[section:non_standard_memset_initialization Non-standard value initialization using `std::memset`]
+
+[*Boost.Container] uses `std::memset` with a zero value to initialize some types as in most platforms this
+initialization yields to the desired value initialization with improved performance.
+
+Following the C11 standard, [*Boost.Container] assumes that ['for any integer type,
+the object representation where all the bits are zero shall be a representation of the value
+zero in that type]. Since `_Bool`/`wchar_t`/`char16_t`/`char32_t` are also integer types in C, it considers
+all C++ integral types as initializable via `std::memset`.
+
+By default, [*Boost.Container] also considers floating point types to be initializable using `std::memset`.
+Most platforms are compatible with this initialization, but in case this initialization is not desirable the
+user can `#define BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_NOT_ZERO` before including library headers.
+
+By default, it also considers pointer types (pointer and pointer to function types, excluding
+member object and member function pointers) to be initializable using `std::memset`.
+Most platforms are compatible with this initialization, but in case this initialization is not desired the
+user can `#define BOOST_CONTAINER_MEMZEROED_POINTER_IS_NOT_ZERO` before including library headers.
+
+If neither `BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_NOT_ZERO` nor
+`BOOST_CONTAINER_MEMZEROED_POINTER_IS_NOT_ZERO` is defined [*Boost.Container] also considers POD
+types to be value initializable via `std::memset` with value zero.
+
+[endsect]
+
+[endsect]
+
+[section:known_issues Known Issues]
+
+[section:move_emulation_limitations Move emulation limitations in C++03 compilers]
+
+[*Boost.Container] uses [*Boost.Move] to implement move semantics both in C++03 and C++11 compilers.
+However, as explained in
+[@http://www.boost.org/doc/libs/release/doc/html/move/emulation_limitations.html Emulation limitations],
+there are some limitations in C++03 compilers that might surprise [*Boost.Container] users.
+
+The most noticeable problem is when [*Boost.Container] containers are placed in a struct with a
+compiler-generated assignment operator:
+
+[c++]
+
+ class holder
+ {
+ boost::container::vector<MyType> vect;
+ };
+
+ void func(const holder& h)
+ {
+ holder copy_h(h); //<--- ERROR: can't convert 'const holder&' to 'holder&'
+ //Compiler-generated copy constructor is non-const:
+ // holder& operator(holder &)
+ //!!!
+ }
+
+This limitation forces the user to define a const version of the copy assignment, in all classes
+holding containers, which might be annoying in some cases.
+
+[endsect]
+
+[endsect]
+
+[section:history_and_reasons History and reasons to use Boost.Container]
+
+[section:boost_container_history Boost.Container history]
+
+[*Boost.Container] is a product of a long development effort that started
+[@http://lists.boost.org/Archives/boost/2004/11/76263.php in 2004 with the experimental Shmem library],
+which pioneered the use of standard containers in shared memory. Shmem included modified SGI STL container
+code tweaked to support non-raw `allocator::pointer` types and stateful allocators. Once reviewed,
+Shmem was accepted as [@http://www.boost.org/libs/interprocess/ Boost.Interprocess] and this library
+continued to refine and improve those containers.
+
+In 2007, container code from node containers (`map`, `list`, `slist`) was rewritten, refactored
+and expanded to build the intrusive container library [@http://www.boost.org/libs/intrusive/ Boost.Intrusive].
+[*Boost.Interprocess] containers were refactored to take advantage of [*Boost.Intrusive] containers and
+code duplication was minimized. Both libraries continued to gain support and bug fixes for years.
+They introduced move semantics, emplacement insertion and more features of then unreleased C++0x
+standard.
+
+[*Boost.Interprocess] containers were always standard compliant, and those containers and new
+containers like `stable_vector` and `flat_[multi]set/map` were used outside [*Boost.Interprocess]
+with success. As containers were mature enough to get their own library, it was a natural step to
+collect them containers and build [*Boost.Container], a library targeted to a wider audience.
+
+[endsect]
+
+
+[section:Why_boost_container Why Boost.Container?]
+
+With so many high quality standard library implementations out there, why would you want to
+use [*Boost.Container]? There are several reasons for that:
+
+* Even if you have a earlier standard conforming compiler, you still can have access to many
+ of the latest C++ standard features and have an easy code migration when you change your compiler.
+* It's compatible with [*Boost.Interprocess] shared memory allocators.
+* You have extremely useful new containers like `[stable/static/small]_vector` and `flat_[multi]set/map`.
+* If you work on multiple platforms, you'll have a portable behaviour without depending
+ on the std-lib implementation conformance of each platform. Some examples:
+ * Default constructors don't allocate memory at all, which improves performance and
+ usually implies a no-throw guarantee (if predicate's or allocator's default constructor doesn't throw).
+ * Small string optimization for [classref boost::container::basic_string basic_string].
+* [link container.extended_functionality Extended functionality] beyond the standard based
+ on user feedback to improve code performance.
+* You need a portable implementation that works when compiling without exceptions support or
+ you need to customize the error handling when a container needs to signal an exceptional error.
+
+[endsect]
+
+[endsect]
+
+[include auto_index_helpers.qbk]
+
+[section:index Indexes]
+
+[named_index class_name Class Index]
+[named_index typedef_name Typedef Index]
+[named_index function_name Function Index]
+[/named_index macro_name Macro Index]
+[/index]
+
+[endsect]
+
+[xinclude autodoc.xml]
+
+[section:acknowledgements_notes Acknowledgements, notes and links]
+
+* Original standard container code comes from [@http://www.sgi.com/tech/stl/ SGI STL library],
+ which enhanced the original HP STL code. Code was rewritten for
+ [*Boost.Interprocess] and moved to [*Boost.Intrusive]. Many thanks to Alexander Stepanov, Meng Lee, David Musser,
+ Matt Austern... and all HP and SGI STL developers.
+
+* `flat_[multi]_map/set` containers were originally based on [@http://en.wikipedia.org/wiki/Loki_%28C%2B%2B%29 Loki's]
+ AssocVector class. Code was rewritten and expanded for [*Boost.Interprocess], so thanks to Andrei Alexandrescu.
+
+* `stable_vector` was invented and coded by
+ [@http://bannalia.blogspot.com/2008/09/introducing-stablevector.html Joaqu\u00EDn M. L\u00F3pez Mu\u00F1oz],
+ then adapted for [*Boost.Interprocess]. Thanks for such a great container.
+
+* `static_vector` was based on Andrew Hundt's and Adam Wulkiewicz's high-performance `varray` class.
+ Many performance improvements of `vector` were also inspired by their implementation. Thanks!
+
+* Howard Hinnant's help and advices were essential when implementing move semantics,
+ improving allocator support or implementing small string optimization. Thanks Howard
+ for your wonderful standard library implementations.
+
+* And finally thanks to all Boosters who helped all these years, improving, fixing and
+ reviewing all my libraries.
+
+[endsect]
+
+[section:release_notes Release Notes]
+
+[section:release_notes_boost_1_68_00 Boost 1.68 Release]
+
+* Improved correctness of [classref boost::container::adaptive_pool adaptive_pool] and many parameters are now compile-time
+ constants instead of runtime constants.
+
+* Implemented C++14's heterogeneous lookup functions for `[multi]map/[multi]set/flat_[multi]map/flat_[multi]set`.
+
+* Added [@https://github.com/boostorg/container/pull/71 GitHub #71: ['"Constructor Template Auto Deduction guides "]].
+
+* Fixed bugs:
+ * [@https://svn.boost.org/trac/boost/ticket/13533 Trac #13533: ['"Boost vector resize causes assert(false)"]].
+ * [@https://github.com/boostorg/container/issues/73 GitHub #73: ['"triviality of pair"]].
+ * [@https://github.com/boostorg/container/issues/74 GitHub #74: ['"vector assignment not using memcpy"]].
+ * [@https://github.com/boostorg/container/issues/75 GitHub #75: ['"flat_set: Heap overflow"]].
+ * [@https://github.com/boostorg/container/issues/76 GitHub #76: ['"flat_set: undefined behaviour on empty range"]].
+ * Fixed race condition bug in [classref boost::container::pmr::unsynchronized_pool_resource unsynchronized_pool_resource]
+ found by Arthur O'Dowyer in his blog post
+ [@https://quuxplusone.github.io/blog/2018/06/05/libcpp-memory-resource/ <memory_resource> for libc++]
+
+* Implemented proposed resolution for
+ [@https://cplusplus.github.io/LWG/issue3120 ['"LWG 3120 Unclear behavior of monotonic_buffer_resource::release()"]].
+ After `release()` the original buffer is recovered for the next allocation.
+
+[endsect]
+
+[section:release_notes_boost_1_67_00 Boost 1.67 Release]
+
+* ['vector] can now have options, using [classref boost::container::vector_options vector_options].
+ The growth factor and the stored size type can be specified.
+
+* Improved range insertion in ['flat_[multi]map/set] containers overall complexity is reduced to O(NlogN).
+
+* Fixed bugs:
+ * [@https://github.com/boostorg/container/pull/61 GitHub #61: ['"Compile problems on Android ndk r16 beta 1"]].
+ * [@https://github.com/boostorg/container/pull/64 GitHub #64: ['"Fix splice for slist"]].
+ * [@https://github.com/boostorg/container/issues/58 GitHub #65: ['"`pmr::monotonic_buffer_resource::allocate()` can return a pointer to freed memory after `release()` is called"]].
+ * [@https://svn.boost.org/trac/boost/ticket/13500 Trac #13500: ['"Memory leak when using erase on string vectors"]].
+
+[endsect]
+
+[section:release_notes_boost_1_66_00 Boost 1.66 Release]
+
+* ['flat_[multi]map/set] can now work as container adaptors, as proposed in [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0429r1.pdf P0429R1].
+ The allocator argument is checked for ['size()] and ['empty()] members. If so, the argument is interpreted as the required underlying container.
+ This means that ['static_vector], ['stable_vector] and ['small_vector] can be used now with flat associative containers.
+
+* Fixed bugs:
+ * [@https://github.com/boostorg/container/pull/54 GitHub #54: ['"no sbrk() in VxWorks, configure dlmalloc to use only mmap"]].
+ * [@https://github.com/boostorg/container/issues/58 GitHub #58: ['"Comparing strings does not compile in gcc 7+ in C++17 mode"]].
+ * [@https://github.com/boostorg/container/issues/59 GitHub #59: ['"basic_string::npos is missing its definition"]].
+
+[endsect]
+
+[section:release_notes_boost_1_65_00 Boost 1.65 Release]
+
+* Implemented `extract_sequence`, `adopt_sequence` functions for flat_[multi]map/set associative containers.
+
+* Fixed bugs:
+ * [@https://github.com/boostorg/container/pull/48 GitHub #48: ['"Replace deprecated/removed C++98 binders"]].
+ * [@https://github.com/boostorg/container/pull/49 GitHub #49: ['"Remove useless allocator copy in map"]].
+ * [@https://github.com/boostorg/container/pull/50 GitHub #50: ['"Fixed bug Trac #13038"]].
+ * [@https://github.com/boostorg/container/pull/51 GitHub #51: ['"Fix integer rollover that triggers clang ubsan when U is unsigned"]].
+
+[endsect]
+
+[section:release_notes_boost_1_64_00 Boost 1.64 Release]
+
+* Fixed bugs:
+ * [@https://svn.boost.org/trac/boost/ticket/11333 Trac #11333: ['"boost::basic_string_ref should interop with boost::container::basic_string"]].
+ * [@https://svn.boost.org/trac/boost/ticket/12749 Trac #12749: ['"container::pmr::polymorphic_allocator compilation error"]].
+ * [@https://svn.boost.org/trac/boost/ticket/12915 Trac #12915: ['"Buffer overflow in boost::container::vector (affects flat_set)"]].
+ * [@https://github.com/boostorg/container/pull/45 GitHub #45: ['"emplace_back must return reference to back(), not to *end()"]].
+ * [@https://github.com/boostorg/container/pull/46 GitHub #46: ['"Fix use of propagate_on_container_swap"]].
+
+[endsect]
+
+[section:release_notes_boost_1_63_00 Boost 1.63 Release]
+
+* Fixed bugs:
+ * [@https://svn.boost.org/trac/boost/ticket/12534 Trac #12534: ['"flat_map fails to compile if included after type_traits is instantiated under gcc"]].
+ * [@https://svn.boost.org/trac/boost/ticket/12577 Trac #12577: ['"Null reference in pair.hpp triggers runtime warning with -fsanitize=undefined"]].
+ * [@https://github.com/boostorg/container/pull/41 GitHub #40: ['Fix parameter types in copy_move_algo.hpp: iterator_traits::difference_type -> allocator_traits::size_type]].
+ * [@https://github.com/boostorg/container/pull/41 GitHub #41: ['Avoid -Wunreachable-code in do_allocate()]].
+
+[endsect]
+
+[section:release_notes_boost_1_62_00 Boost 1.62 Release]
+
+* Fixed bugs:
+ * [@https://svn.boost.org/trac/boost/ticket/9481 Trac #9481: ['"Minor comment typo in Boost.Container"]].
+ * [@https://svn.boost.org/trac/boost/ticket/9689 Trac #9689: ['"Add piecewise_construct to boost::container"]].
+ * [@https://svn.boost.org/trac/boost/ticket/11170 Trac #11170: ['"Doc slip for index_of"]].
+ * [@https://svn.boost.org/trac/boost/ticket/11802 Trac #11802: ['"Incorrect ordering after using insert() with ordered_range_t on a flat_multiset with a non-default sort order"]].
+ * [@https://svn.boost.org/trac/boost/ticket/12117 Trac #12117: ['"flat_set constructor with ordered_unique_range"]].
+ * [@https://svn.boost.org/trac/boost/ticket/12177 Trac #12177: ['"vector::priv_merge uses unqualified uintptr_t"]].
+ * [@https://svn.boost.org/trac/boost/ticket/12183 Trac #12183: ['"GCC 6.1 thinks boost::container::string violates strict aliasing"]].
+ * [@https://svn.boost.org/trac/boost/ticket/12256 Trac #12256: ['"set<std::pair<int,int>>::insert cause compilation error in debug configuration in Visual Studio 2012"]].
+ * [@https://svn.boost.org/trac/boost/ticket/12273 Trac #12273: ['"static_vector max_size() and capacity() should be constant expressions"]].
+ Added constant `static_vector<>::static_capacity` to use the configured capacity in constant expressions.
+ * [@https://svn.boost.org/trac/boost/ticket/12286 Trac #12286: ['"PMR flat_map from Boost Container does not compile"]].
+ * [@https://svn.boost.org/trac/boost/ticket/12296 Trac #12296: ['"{deque,string} combine for a memory leak"]].
+ * [@https://svn.boost.org/trac/boost/ticket/12319 Trac #12319: ['"flat_set` should be nothrow move constructible"]].
+
+* Revised noexcept expressions of default and move constructors in all containers.
+* Implemented C++17's `insert_or_assign`/`try_emplace` for [classref boost::container::map map] and [classref boost::container::flat_map flat_map].
+* Implemented C++17's [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0083r3.pdf ['Splicing Maps and Sets (Revision 5)]]
+ for [classref boost::container::map map], [classref boost::container::multimap multimap],
+ [classref boost::container::set set], [classref boost::container::multiset multiset].
+* Implemented C++17's [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0084r2.pdf ['P0084R2 Emplace Return Type]]
+ in `deque`, `vector`, `stable_vector`, `small_vector`, `static_vector`, `list` and `slist`.
+
+[endsect]
+
+[section:release_notes_boost_1_61_00 Boost 1.61 Release]
+
+* [classref boost::container::small_vector] supports more constructors and assignments.
+* Fixed bugs:
+ * [@https://svn.boost.org/trac/boost/ticket/11820 Trac #11820: ['"compiler error when using operator[] of map"]].
+ * [@https://svn.boost.org/trac/boost/ticket/11856 Trac #11856: ['"pool_resource.cpp error: declaration changes meaning"]].
+ * [@https://svn.boost.org/trac/boost/ticket/11866 Trac #11866: ['"small_vector does not have range constructor"]].
+ * [@https://svn.boost.org/trac/boost/ticket/11867 Trac #11867: ['"small_vector should have constructor and assignment operator taking other small_vector"]].
+ * [@https://svn.boost.org/trac/boost/ticket/11912 Trac #11912: ['"flat_map use of vector::priv_forward_range_insert_expand_backwards may cause move with same source"]].
+ * [@https://svn.boost.org/trac/boost/ticket/11957 Trac #11957: ['"static_vector::max_size() is higher than the capacity"]].
+ * [@https://svn.boost.org/trac/boost/ticket/12014 Trac #12014: ['"boost::container::set can not insert const (ref) range"]].
+ * [@https://github.com/boostorg/container/pull/33 GitHub #33: ['Make sure std::string constructor is available]].
+
+[endsect]
+
+[section:release_notes_boost_1_60_00 Boost 1.60 Release]
+
+* Implemented [link container.cpp_conformance.polymorphic_memory_resources Polymorphic Memory Resources].
+* Add more BOOST_ASSERT checks to test preconditions in some operations (like `pop_back`, `pop_front`, `back`, `front`, etc.)
+* Added C++11 `back`/`front` operations to [classref boost::container::basic_string basic_string].
+* Fixed bugs:
+ * [@https://svn.boost.org/trac/boost/ticket/11627 Trac #11627: ['"small_vector<T,n>::swap() appears to be broken"]].
+ * [@https://svn.boost.org/trac/boost/ticket/11628 Trac #11628: ['"small_vector<int,n> iterates over elements in destructor"]].
+ * [@https://svn.boost.org/trac/boost/ticket/11697 Trac #11697: ['"Wrong initialization order in tuple copy-constructor"]].
+ * [@https://svn.boost.org/trac/boost/ticket/11698 Trac #11698: ['"Missing return statement in static_storage_allocator"]].
+ * [@https://github.com/boostorg/container/pull/29 GitHub #29: ['Doc fixes for flap_map complexity requirements]].
+ * [@https://github.com/boostorg/container/pull/31 GitHub #31: ['DL_SIZE_IMPL also dereference addr]].
+
+[endsect]
+
+[section:release_notes_boost_1_59_00 Boost 1.59 Release]
+
+* [@https://github.com/boostorg/container/pull/26 GitHub #26: ['Fix bug in stable_vector::capacity()]]. Thanks to timsong-cpp/Arindam Mukerjee.
+* [@https://github.com/boostorg/container/pull/27 GitHub #27: ['fix stable_vector's index_of's doxygen comment]]. Thanks to kariya-mitsuru.
+* [@https://svn.boost.org/trac/boost/ticket/11380 Trac #11380: ['"Container library std forward declarations incorrect in std_fwd.hpp on libc++ with gcc"]].
+* [@https://svn.boost.org/trac/boost/ticket/11388 Trac #11388: ['"boost::container::list::emplace_back broken on Visual Studio 2010"]].
+* [@https://svn.boost.org/trac/boost/ticket/11339 Trac #11339: ['"VC12 LNK2005 error with boost::container::adaptive_pool"]].
+
+[endsect]
+
+[section:release_notes_boost_1_58_00 Boost 1.58 Release]
+* Experimental [classref boost::container::small_vector small_vector] container.
+* Massive dependency reorganization. Now [*Boost.Container] depends on very basic utilities like Boost.Core
+ and [*Boost.Intrusive]. Preprocessed code size have decreased considerably and compilation times have improved.
+* Added `nth` and `index_of` functions to containers with random-access iterators (except `basic_string`).
+* Added C++17's `allocator_traits<Allocator>::is_always_equal`.
+* Updated containers to implement new constructors as specified in
+ [@http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2210 2210. Missing allocator-extended constructor for allocator-aware containers].
+* Fixed bugs:
+ * [@https://svn.boost.org/trac/boost/ticket/9931 Trac #9931: ['"flat_map::insert(ordered_unique_range_t...) fails with move_iterators"]] (reopened).
+ * [@https://svn.boost.org/trac/boost/ticket/11076 Trac #11076: ['"Unqualified calls to memmove/memcpy in container/detail/copy_move_algo.hpp"]].
+ * [@https://svn.boost.org/trac/boost/ticket/10790 Trac #10790 (['"long long errors from container"])].
+ * [@https://svn.boost.org/trac/boost/ticket/10808 Trac #10808 (['"compare equal operator of vector is broken"])].
+ * [@https://svn.boost.org/trac/boost/ticket/10930 Trac #10930 (['"container std_fwd.hpp neglects custom std namespaces"])].
+ * [@https://svn.boost.org/trac/boost/ticket/11139 Trac #11139 (['"boost::container::vector<std::shared_ptr<const T>...>::const_iterator allows changing dereferenced elements"])].
+* [*Source Breaking]: [classref boost::container::scoped_allocator_adaptor scoped_allocator_adaptor]'s
+ `propagate_on_container_copy_assignment`, `propagate_on_container_move_assignment` and `propagate_on_container_swap`
+ are no longer `::boost::integral_constant<bool, true/false>` types. The dependency reorganization needed to break
+ with those classes to avoid MPL dependencies, and interoperability with `std::integral_constant` was not guaranteed.
+ Code assumming `boost::true_type/boost::false_type` on this will not compile. As a workaround, use the guaranteed internal
+ `::value` constant: `::boost::integral_constant<bool, scoped_allocator_adaptor<Allocator>::propagate_on_container_move_assignment::value>`.
+
+[endsect]
+
+[section:release_notes_boost_1_57_00 Boost 1.57 Release]
+* Added support for `initializer_list`. Contributed by Robert Matusewicz.
+* Fixed double destruction bugs in vector and backward expansion capable allocators.
+* Fixed bugs:
+ * [@https://svn.boost.org/trac/boost/ticket/10263 Trac #10263 (['"AIX 6.1 bug with sched_yield() function out of scope"])].
+ * [@https://github.com/boostorg/container/pull/16 GitHub #16: ['Fix iterators of incomplete type containers]]. Thanks to Mikael Persson.
+
+[endsect]
+
+[section:release_notes_boost_1_56_00 Boost 1.56 Release]
+
+* Added DlMalloc-based [link container.extended_allocators Extended Allocators].
+
+* [link container.configurable_containers.configurable_tree_based_associative_containers Improved configurability]
+ of tree-based ordered associative containers. AVL, Scapegoat and Splay trees are now available
+ to implement [classref boost::container::set set], [classref boost::container::multiset multiset],
+ [classref boost::container::map map] and [classref boost::container::multimap multimap].
+
+* Fixed bugs:
+ * [@https://svn.boost.org/trac/boost/ticket/9338 #9338: ['"VS2005 compiler errors in swap() definition after including container/memory_util.hpp"]].
+ * [@https://svn.boost.org/trac/boost/ticket/9637 #9637: ['"Boost.Container vector::resize() performance issue"]].
+ * [@https://svn.boost.org/trac/boost/ticket/9648 #9648: ['"string construction optimization - char_traits::copy could be used ..."]].
+ * [@https://svn.boost.org/trac/boost/ticket/9801 #9801: ['"I can no longer create and iterator_range from a stable_vector"]].
+ * [@https://svn.boost.org/trac/boost/ticket/9915 #9915: ['"Documentation issues regarding vector constructors and resize methods - value/default initialization"]].
+ * [@https://svn.boost.org/trac/boost/ticket/9916 #9916: ['"Allocator propagation incorrect in the assignment operator of most"]].
+ * [@https://svn.boost.org/trac/boost/ticket/9931 #9931: ['"flat_map::insert(ordered_unique_range_t...) fails with move_iterators"]].
+ * [@https://svn.boost.org/trac/boost/ticket/9955 #9955: ['"Using memcpy with overlapped buffers in vector"]].
+
+[endsect]
+
+[section:release_notes_boost_1_55_00 Boost 1.55 Release]
+
+* Implemented [link container.main_features.scary_iterators SCARY iterators].
+
+* Fixed bugs [@https://svn.boost.org/trac/boost/ticket/8269 #8269],
+ [@https://svn.boost.org/trac/boost/ticket/8473 #8473],
+ [@https://svn.boost.org/trac/boost/ticket/8892 #8892],
+ [@https://svn.boost.org/trac/boost/ticket/9009 #9009],
+ [@https://svn.boost.org/trac/boost/ticket/9064 #9064],
+ [@https://svn.boost.org/trac/boost/ticket/9092 #9092],
+ [@https://svn.boost.org/trac/boost/ticket/9108 #9108],
+ [@https://svn.boost.org/trac/boost/ticket/9166 #9166].
+
+* Added `default initialization` insertion functions to vector-like containers
+ with new overloads taking `default_init_t` as an argument instead of `const value_type &`.
+
+[endsect]
+
+[section:release_notes_boost_1_54_00 Boost 1.54 Release]
+
+* Added experimental `static_vector` class, based on Andrew Hundt's and Adam Wulkiewicz's
+ high performance `varray` class.
+* Speed improvements in `vector` constructors/copy/move/swap, dispatching to memcpy when possible.
+* Support for `BOOST_NO_EXCEPTIONS` [@https://svn.boost.org/trac/boost/ticket/7227 #7227].
+* Fixed bugs [@https://svn.boost.org/trac/boost/ticket/7921 #7921],
+ [@https://svn.boost.org/trac/boost/ticket/7969 #7969],
+ [@https://svn.boost.org/trac/boost/ticket/8118 #8118],
+ [@https://svn.boost.org/trac/boost/ticket/8294 #8294],
+ [@https://svn.boost.org/trac/boost/ticket/8553 #8553],
+ [@https://svn.boost.org/trac/boost/ticket/8724 #8724].
+
+[endsect]
+
+[section:release_notes_boost_1_53_00 Boost 1.53 Release]
+
+* Fixed bug [@https://svn.boost.org/trac/boost/ticket/7650 #7650].
+* Improved `vector`'s insertion performance.
+* Changed again experimental multiallocation interface for better performance (still experimental).
+* Added no exception support for those willing to disable exceptions in their compilers.
+* Fixed GCC -Wshadow warnings.
+* Replaced deprecated BOOST_NO_XXXX with newer BOOST_NO_CXX11_XXX macros.
+
+[endsect]
+
+[section:release_notes_boost_1_52_00 Boost 1.52 Release]
+
+* Improved `stable_vector`'s template code bloat and type safety.
+* Changed typedefs and reordered functions of sequence containers to improve doxygen documentation.
+* Fixed bugs
+ [@https://svn.boost.org/trac/boost/ticket/6615 #6615],
+ [@https://svn.boost.org/trac/boost/ticket/7139 #7139],
+ [@https://svn.boost.org/trac/boost/ticket/7215 #7215],
+ [@https://svn.boost.org/trac/boost/ticket/7232 #7232],
+ [@https://svn.boost.org/trac/boost/ticket/7269 #7269],
+ [@https://svn.boost.org/trac/boost/ticket/7439 #7439].
+* Implemented LWG Issue #149 (range insertion now returns an iterator) & cleaned up insertion code in most containers
+* Corrected aliasing errors.
+
+[endsect]
+
+[section:release_notes_boost_1_51_00 Boost 1.51 Release]
+
+* Fixed bugs
+ [@https://svn.boost.org/trac/boost/ticket/6763 #6763],
+ [@https://svn.boost.org/trac/boost/ticket/6803 #6803],
+ [@https://svn.boost.org/trac/boost/ticket/7114 #7114],
+ [@https://svn.boost.org/trac/boost/ticket/7103 #7103].
+ [@https://svn.boost.org/trac/boost/ticket/7123 #7123],
+
+[endsect]
+
+[section:release_notes_boost_1_50_00 Boost 1.50 Release]
+
+* Added Scoped Allocator Model support.
+
+* Fixed bugs
+ [@https://svn.boost.org/trac/boost/ticket/6606 #6606],
+ [@https://svn.boost.org/trac/boost/ticket/6533 #6533],
+ [@https://svn.boost.org/trac/boost/ticket/6536 #6536],
+ [@https://svn.boost.org/trac/boost/ticket/6566 #6566],
+ [@https://svn.boost.org/trac/boost/ticket/6575 #6575],
+
+[endsect]
+
+
+[section:release_notes_boost_1_49_00 Boost 1.49 Release]
+
+* Fixed bugs
+ [@https://svn.boost.org/trac/boost/ticket/6540 #6540],
+ [@https://svn.boost.org/trac/boost/ticket/6499 #6499],
+ [@https://svn.boost.org/trac/boost/ticket/6336 #6336],
+ [@https://svn.boost.org/trac/boost/ticket/6335 #6335],
+ [@https://svn.boost.org/trac/boost/ticket/6287 #6287],
+ [@https://svn.boost.org/trac/boost/ticket/6205 #6205],
+ [@https://svn.boost.org/trac/boost/ticket/4383 #4383].
+
+* Added `allocator_traits` support for both C++11 and C++03
+ compilers through an internal `allocator_traits` clone.
+
+[endsect]
+
+[section:release_notes_boost_1_48_00 Boost 1.48 Release]
+
+* First release. Container code from [*Boost.Interprocess] was deleted
+ and redirected to [*Boost.Container ] via using directives.
+
+[endsect]
+
+[endsect]