1 ////////////////////////////////////////////////////////////////////////////// 2 // 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) 6 // 7 // See http://www.boost.org/libs/container for documentation. 8 // 9 ////////////////////////////////////////////////////////////////////////////// 10 //[doc_custom_small_vector 11 #include <boost/container/small_vector.hpp> 12 #include <boost/static_assert.hpp> 13 14 //Make sure assertions are active 15 #ifdef NDEBUG 16 #undef NDEBUG 17 #endif 18 #include <cassert> 19 main()20int main () 21 { 22 using namespace boost::container; 23 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; 26 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); 30 31 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; 35 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); 40 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); 44 45 return 0; 46 } 47 //] 48