1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2013-2013. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/container for documentation.
9 //////////////////////////////////////////////////////////////////////////////
10 //[doc_custom_small_vector
11 #include <boost/container/small_vector.hpp>
12 #include <boost/static_assert.hpp>
14 //Make sure assertions are active
22 using namespace boost::container
;
24 //This option specifies the desired alignment for the internal value_type
25 typedef small_vector_options
< inplace_alignment
<16u> >::type alignment_16_option_t
;
27 //Check 16 byte alignment option
28 small_vector
<int, 10, void, alignment_16_option_t
> sv
;
29 assert(((std::size_t)sv
.data() % 16u) == 0);
32 //This option specifies that a vector will increase its capacity 50%
33 //each time the previous capacity was exhausted.
34 typedef small_vector_options
< growth_factor
<growth_factor_50
> >::type growth_50_option_t
;
36 //Fill the vector until full capacity is reached
37 small_vector
<int, 10, void, growth_50_option_t
> growth_50_vector(10, 0);
38 const std::size_t old_cap
= growth_50_vector
.capacity();
39 growth_50_vector
.resize(old_cap
);
41 //Now insert an additional item and check the new buffer is 50% bigger
42 growth_50_vector
.push_back(1);
43 assert(growth_50_vector
.capacity() == old_cap
*3/2);