summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/container/bench
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/container/bench
parentInitial commit. (diff)
downloadceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz
ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/container/bench')
-rw-r--r--src/boost/libs/container/bench/Jamfile.v234
-rw-r--r--src/boost/libs/container/bench/bench_adaptive_node_pool.cpp339
-rw-r--r--src/boost/libs/container/bench/bench_alloc.cpp188
-rw-r--r--src/boost/libs/container/bench/bench_alloc_expand_bwd.cpp224
-rw-r--r--src/boost/libs/container/bench/bench_alloc_expand_fwd.cpp202
-rw-r--r--src/boost/libs/container/bench/bench_alloc_shrink_to_fit.cpp181
-rw-r--r--src/boost/libs/container/bench/bench_alloc_stable_vector_burst.cpp294
-rw-r--r--src/boost/libs/container/bench/bench_flat_multiset.cpp29
-rw-r--r--src/boost/libs/container/bench/bench_flat_set.cpp29
-rw-r--r--src/boost/libs/container/bench/bench_set.cpp35
-rw-r--r--src/boost/libs/container/bench/bench_set.hpp485
-rw-r--r--src/boost/libs/container/bench/bench_set_adaptive_pool.cpp34
-rw-r--r--src/boost/libs/container/bench/bench_set_alloc_v2.cpp29
-rw-r--r--src/boost/libs/container/bench/bench_set_avl.cpp38
-rw-r--r--src/boost/libs/container/bench/bench_set_multi.cpp30
-rw-r--r--src/boost/libs/container/bench/bench_set_sg.cpp28
-rw-r--r--src/boost/libs/container/bench/bench_set_sp.cpp28
-rw-r--r--src/boost/libs/container/bench/bench_static_vector.cpp144
-rw-r--r--src/boost/libs/container/bench/detail/varray.hpp2242
-rw-r--r--src/boost/libs/container/bench/detail/varray_concept.hpp60
-rw-r--r--src/boost/libs/container/bench/detail/varray_util.hpp646
-rw-r--r--src/boost/libs/container/bench/varray.hpp1000
22 files changed, 6319 insertions, 0 deletions
diff --git a/src/boost/libs/container/bench/Jamfile.v2 b/src/boost/libs/container/bench/Jamfile.v2
new file mode 100644
index 000000000..9cf993dc4
--- /dev/null
+++ b/src/boost/libs/container/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/src/boost/libs/container/bench/bench_adaptive_node_pool.cpp b/src/boost/libs/container/bench/bench_adaptive_node_pool.cpp
new file mode 100644
index 000000000..acb0750ee
--- /dev/null
+++ b/src/boost/libs/container/bench/bench_adaptive_node_pool.cpp
@@ -0,0 +1,339 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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
+ #define SIMPLE_IT
+ #ifdef SINGLE_TEST
+ #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 };
+ #elif defined(SIMPLE_IT)
+ std::size_t numrep [] = { 3 };
+ std::size_t numele [] = { 100 };
+ #else
+ #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 };
+ #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/src/boost/libs/container/bench/bench_alloc.cpp b/src/boost/libs/container/bench/bench_alloc.cpp
new file mode 100644
index 000000000..e17be111a
--- /dev/null
+++ b/src/boost/libs/container/bench/bench_alloc.cpp
@@ -0,0 +1,188 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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
+ #define SIMPLE_IT
+ #ifdef SINGLE_TEST
+ #ifdef NDEBUG
+ unsigned int numrep [] = { 50000 };
+ #else
+ unsigned int numrep [] = { 5000 };
+ #endif
+ unsigned int numele [] = { 100 };
+ #elif defined(SIMPLE_IT)
+ unsigned int numrep [] = { 3 };
+ unsigned int numele [] = { 100 };
+ #else
+ #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 };
+ #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/src/boost/libs/container/bench/bench_alloc_expand_bwd.cpp b/src/boost/libs/container/bench/bench_alloc_expand_bwd.cpp
new file mode 100644
index 000000000..d60cf5647
--- /dev/null
+++ b/src/boost/libs/container/bench/bench_alloc_expand_bwd.cpp
@@ -0,0 +1,224 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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
+ #define SIMPLE_IT
+ #ifdef SINGLE_TEST
+ #ifdef NDEBUG
+ unsigned int numit [] = { 10 };
+ #else
+ unsigned int numit [] = { 10 };
+ #endif
+ unsigned int numele [] = { 10000 };
+ #elif defined(SIMPLE_IT)
+ unsigned int numit [] = { 3 };
+ unsigned int numele[] = { 10000 };
+ #else
+ #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 };
+ #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/src/boost/libs/container/bench/bench_alloc_expand_fwd.cpp b/src/boost/libs/container/bench/bench_alloc_expand_fwd.cpp
new file mode 100644
index 000000000..d03a75e78
--- /dev/null
+++ b/src/boost/libs/container/bench/bench_alloc_expand_fwd.cpp
@@ -0,0 +1,202 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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
+ #define SIMPLE_IT
+ #ifdef SINGLE_TEST
+ #ifdef NDEBUG
+ std::size_t numit [] = { 1000 };
+ #else
+ std::size_t numit [] = { 100 };
+ #endif
+ std::size_t numele [] = { 10000 };
+ #elif defined SIMPLE_IT
+ std::size_t numit [] = { 3 };
+ std::size_t numele [] = { 10000 };
+ #else
+ #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 };
+ #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/src/boost/libs/container/bench/bench_alloc_shrink_to_fit.cpp b/src/boost/libs/container/bench/bench_alloc_shrink_to_fit.cpp
new file mode 100644
index 000000000..0edb2feab
--- /dev/null
+++ b/src/boost/libs/container/bench/bench_alloc_shrink_to_fit.cpp
@@ -0,0 +1,181 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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
+ #define SIMPLE_IT
+ #ifdef SINGLE_TEST
+ #ifdef NDEBUG
+ unsigned int numit [] = { 10 };
+ #else
+ unsigned int numit [] = { 50 };
+ unsigned int numele[] = { 2000 };
+ #endif
+ #elif defined SIMPLE_IT
+ unsigned int numit [] = { 3 };
+ unsigned int numele[] = { 2000 };
+ #else
+ #ifdef NDEBUG
+ unsigned int numit [] = { 100, 1000, 10000 };
+ #else
+ unsigned int numit [] = { 10, 100, 1000 };
+ #endif
+ unsigned int numele [] = { 10000, 2000, 500 };
+ #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/src/boost/libs/container/bench/bench_alloc_stable_vector_burst.cpp b/src/boost/libs/container/bench/bench_alloc_stable_vector_burst.cpp
new file mode 100644
index 000000000..1e299b31a
--- /dev/null
+++ b/src/boost/libs/container/bench/bench_alloc_stable_vector_burst.cpp
@@ -0,0 +1,294 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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
+ #define SIMPLE_IT
+ #ifdef SINGLE_TEST
+ #ifdef NDEBUG
+ unsigned int numit [] = { 40 };
+ #else
+ unsigned int numit [] = { 4 };
+ #endif
+ unsigned int numele [] = { 10000 };
+ #elif defined(SIMPLE_IT)
+ unsigned int numit [] = { 3 };
+ unsigned int numele [] = { 10000 };
+ #else
+ #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 };
+ #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/src/boost/libs/container/bench/bench_flat_multiset.cpp b/src/boost/libs/container/bench/bench_flat_multiset.cpp
new file mode 100644
index 000000000..6ee7cca1a
--- /dev/null
+++ b/src/boost/libs/container/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/src/boost/libs/container/bench/bench_flat_set.cpp b/src/boost/libs/container/bench/bench_flat_set.cpp
new file mode 100644
index 000000000..8f86ba467
--- /dev/null
+++ b/src/boost/libs/container/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/src/boost/libs/container/bench/bench_set.cpp b/src/boost/libs/container/bench/bench_set.cpp
new file mode 100644
index 000000000..890fd3507
--- /dev/null
+++ b/src/boost/libs/container/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/src/boost/libs/container/bench/bench_set.hpp b/src/boost/libs/container/bench/bench_set.hpp
new file mode 100644
index 000000000..300aba474
--- /dev/null
+++ b/src/boost/libs/container/bench/bench_set.hpp
@@ -0,0 +1,485 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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;
+
+#define SIMPLE_IT
+#ifdef SIMPLE_IT
+static const std::size_t NIter = 3;
+#else
+ #ifdef NDEBUG
+ static const std::size_t NIter = 250;
+ #else
+ static const std::size_t NIter = 25;
+ #endif
+#endif
+
+static const std::size_t NElements = 1000;
+
+
+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 j = 0, max = unique_range.size(); j != max; ++j){
+ v_it[j] = c.find(unique_range[j]);
+ }
+ 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 j = 0, max = unique_range.size(); j != max; ++j){
+ v_it[j] = c.lower_bound(unique_range[j]);
+ }
+ 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 j = 0, max = unique_range.size(); j != max; ++j){
+ v_it[j] = c.upper_bound(unique_range[j]);
+ }
+ 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 j = 0, max = unique_range.size(); j != max; ++j){
+ v_itp[j] = c.equal_range(unique_range[j]);
+ }
+ 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 j = 0, max = unique_range.size(); j != max; ++j){
+ count += c.count(unique_range[j]);
+ }
+ 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/src/boost/libs/container/bench/bench_set_adaptive_pool.cpp b/src/boost/libs/container/bench/bench_set_adaptive_pool.cpp
new file mode 100644
index 000000000..dc5f4762c
--- /dev/null
+++ b/src/boost/libs/container/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/src/boost/libs/container/bench/bench_set_alloc_v2.cpp b/src/boost/libs/container/bench/bench_set_alloc_v2.cpp
new file mode 100644
index 000000000..9c2fb9bee
--- /dev/null
+++ b/src/boost/libs/container/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/src/boost/libs/container/bench/bench_set_avl.cpp b/src/boost/libs/container/bench/bench_set_avl.cpp
new file mode 100644
index 000000000..6d0d77d73
--- /dev/null
+++ b/src/boost/libs/container/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/src/boost/libs/container/bench/bench_set_multi.cpp b/src/boost/libs/container/bench/bench_set_multi.cpp
new file mode 100644
index 000000000..a01dbc9f9
--- /dev/null
+++ b/src/boost/libs/container/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/src/boost/libs/container/bench/bench_set_sg.cpp b/src/boost/libs/container/bench/bench_set_sg.cpp
new file mode 100644
index 000000000..c98843884
--- /dev/null
+++ b/src/boost/libs/container/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/src/boost/libs/container/bench/bench_set_sp.cpp b/src/boost/libs/container/bench/bench_set_sp.cpp
new file mode 100644
index 000000000..0f86ed486
--- /dev/null
+++ b/src/boost/libs/container/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/src/boost/libs/container/bench/bench_static_vector.cpp b/src/boost/libs/container/bench/bench_static_vector.cpp
new file mode 100644
index 000000000..d9dd8a789
--- /dev/null
+++ b/src/boost/libs/container/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/src/boost/libs/container/bench/detail/varray.hpp b/src/boost/libs/container/bench/detail/varray.hpp
new file mode 100644
index 000000000..6db4f1e5f
--- /dev/null
+++ b/src/boost/libs/container/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, other.size());
+ }
+
+ // 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/src/boost/libs/container/bench/detail/varray_concept.hpp b/src/boost/libs/container/bench/detail/varray_concept.hpp
new file mode 100644
index 000000000..94d19bd79
--- /dev/null
+++ b/src/boost/libs/container/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/src/boost/libs/container/bench/detail/varray_util.hpp b/src/boost/libs/container/bench/detail/varray_util.hpp
new file mode 100644
index 000000000..cf8c33791
--- /dev/null
+++ b/src/boost/libs/container/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 , I ,
+ 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/src/boost/libs/container/bench/varray.hpp b/src/boost/libs/container/bench/varray.hpp
new file mode 100644
index 000000000..98b710078
--- /dev/null
+++ b/src/boost/libs/container/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