mirror of
https://github.com/boostorg/container.git
synced 2026-02-26 04:32:21 +00:00
Make customization example more clear with a heading before each option
This commit is contained in:
@@ -20,6 +20,10 @@ int main ()
|
||||
{
|
||||
using namespace boost::container;
|
||||
|
||||
//--------------------------------------------
|
||||
// 'stored_size' option
|
||||
//--------------------------------------------
|
||||
|
||||
//This option specifies that a deque that will use "unsigned char" as
|
||||
//the type to store capacity or size internally.
|
||||
typedef deque_options< stored_size<unsigned char> >::type size_option_t;
|
||||
@@ -43,6 +47,10 @@ int main ()
|
||||
|
||||
assert(exception_thrown == true);
|
||||
|
||||
//--------------------------------------------
|
||||
// 'block_size' option
|
||||
//--------------------------------------------
|
||||
|
||||
//This option specifies the desired block size for deque
|
||||
typedef deque_options< block_size<128u> >::type block_128_option_t;
|
||||
|
||||
@@ -50,6 +58,10 @@ int main ()
|
||||
typedef deque<int, void, block_128_option_t > block_128_deque_t;
|
||||
assert(block_128_deque_t::get_block_size() == 128u);
|
||||
|
||||
//--------------------------------------------
|
||||
// 'block_bytes' option
|
||||
//--------------------------------------------
|
||||
|
||||
//This option specifies the maximum block size for deque
|
||||
//in bytes
|
||||
typedef deque_options< block_bytes<1024u> >::type block_1024_bytes_option_t;
|
||||
|
||||
@@ -20,9 +20,10 @@ int main ()
|
||||
{
|
||||
using namespace boost::container;
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// 'stored_size' option
|
||||
////////////////////////////////////////////////
|
||||
//--------------------------------------------
|
||||
// 'stored_size' option
|
||||
//--------------------------------------------
|
||||
|
||||
//Specify that a devector will use "unsigned char" as the type to store size/capacity
|
||||
typedef devector_options< stored_size<unsigned char> >::type size_option_t;
|
||||
|
||||
@@ -43,9 +44,10 @@ int main ()
|
||||
//=catch(...){ exception_thrown = true; }
|
||||
assert(exception_thrown == true);
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// 'growth_factor' option
|
||||
////////////////////////////////////////////////
|
||||
//--------------------------------------------
|
||||
// 'growth_factor' option
|
||||
//--------------------------------------------
|
||||
|
||||
//Specify that a devector will increase its capacity 50% when reallocating
|
||||
typedef devector_options< growth_factor<growth_factor_50> >::type growth_50_option_t;
|
||||
|
||||
@@ -58,9 +60,9 @@ int main ()
|
||||
growth_50_dv.push_back(1);
|
||||
assert(growth_50_dv.capacity() == old_cap*3/2);
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// 'relocate_on' option
|
||||
////////////////////////////////////////////////
|
||||
//--------------------------------------------
|
||||
// 'relocate_on' option
|
||||
//--------------------------------------------
|
||||
|
||||
//Specifies that a devector will not reallocate but relocate elements if the free space
|
||||
//at one end is exhausted and the total load factor is below the 66% threshold.
|
||||
|
||||
@@ -20,6 +20,10 @@ int main ()
|
||||
{
|
||||
using namespace boost::container;
|
||||
|
||||
//--------------------------------------------
|
||||
// 'inplace_alignment' option
|
||||
//--------------------------------------------
|
||||
|
||||
//This option specifies the desired alignment for the internal value_type
|
||||
typedef small_vector_options< inplace_alignment<16u> >::type alignment_16_option_t;
|
||||
|
||||
@@ -27,6 +31,9 @@ int main ()
|
||||
small_vector<int, 10, void, alignment_16_option_t > sv;
|
||||
assert(((std::size_t)sv.data() % 16u) == 0);
|
||||
|
||||
//--------------------------------------------
|
||||
// 'growth_factor' option
|
||||
//--------------------------------------------
|
||||
|
||||
//This option specifies that a vector will increase its capacity 50%
|
||||
//each time the previous capacity was exhausted.
|
||||
@@ -41,6 +48,10 @@ int main ()
|
||||
growth_50_vector.push_back(1);
|
||||
assert(growth_50_vector.capacity() == old_cap*3/2);
|
||||
|
||||
//--------------------------------------------
|
||||
// 'stored_size' option
|
||||
//--------------------------------------------
|
||||
|
||||
//This option specifies that a vector that will use "unsigned char" as
|
||||
//the type to store capacity or size internally.
|
||||
typedef small_vector_options< stored_size<unsigned char> >::type size_option_t;
|
||||
|
||||
@@ -20,6 +20,10 @@ int main ()
|
||||
{
|
||||
using namespace boost::container;
|
||||
|
||||
//--------------------------------------------
|
||||
// 'inplace_alignment' option
|
||||
//--------------------------------------------
|
||||
|
||||
//This option specifies the desired alignment for value_type
|
||||
typedef static_vector_options< inplace_alignment<16u> >::type alignment_16_option_t;
|
||||
|
||||
@@ -27,12 +31,20 @@ int main ()
|
||||
static_vector<int, 10, alignment_16_option_t > sv;
|
||||
assert(((std::size_t)sv.data() % 16u) == 0);
|
||||
|
||||
//--------------------------------------------
|
||||
// 'throw_on_overflow' option
|
||||
//--------------------------------------------
|
||||
|
||||
//This static_vector won't throw on overflow, for maximum performance
|
||||
typedef static_vector_options< throw_on_overflow<false> >::type no_throw_options_t;
|
||||
|
||||
//Create static_vector with no throw on overflow
|
||||
static_vector<int, 10, no_throw_options_t > sv2;
|
||||
|
||||
//--------------------------------------------
|
||||
// 'stored_size' option
|
||||
//--------------------------------------------
|
||||
|
||||
//This options specifies that internal `size()` can be represented by an unsigned char
|
||||
//instead of the default `std::size_t`.
|
||||
typedef static_vector_options< stored_size<unsigned char> >::type stored_size_uchar_t;
|
||||
|
||||
@@ -21,46 +21,49 @@ int main ()
|
||||
using namespace boost::container;
|
||||
|
||||
//First define several options
|
||||
//
|
||||
|
||||
//--------------------------------------------
|
||||
// 'tree_type' option
|
||||
//--------------------------------------------
|
||||
|
||||
//This option specifies an AVL tree based associative container
|
||||
typedef tree_assoc_options< tree_type<avl_tree> >::type AVLTree;
|
||||
|
||||
//This option specifies an Splay tree based associative container
|
||||
typedef tree_assoc_options< tree_type<splay_tree> >::type SplayTree;
|
||||
|
||||
//Splay tree based multiset container
|
||||
typedef multiset<int, std::less<int>, new_allocator<int>, SplayTree> SplayMultiset;
|
||||
|
||||
//AVLTree based set container
|
||||
typedef set<int, std::less<int>, new_allocator<int>, AVLTree> AvlSet;
|
||||
|
||||
AvlSet avl_set;
|
||||
avl_set.insert(0);
|
||||
assert(avl_set.find(0) != avl_set.end());
|
||||
|
||||
SplayMultiset splay_mset;
|
||||
splay_mset.insert(2);
|
||||
splay_mset.insert(2);
|
||||
assert(splay_mset.count(2) == 2);
|
||||
|
||||
//--------------------------------------------
|
||||
// 'optimize_size' option
|
||||
//--------------------------------------------
|
||||
|
||||
//This option specifies an AVL tree based associative container
|
||||
//disabling node size optimization.
|
||||
typedef tree_assoc_options< tree_type<avl_tree>
|
||||
, optimize_size<false> >::type AVLTreeNoSizeOpt;
|
||||
|
||||
//This option specifies an Splay tree based associative container
|
||||
typedef tree_assoc_options< tree_type<splay_tree> >::type SplayTree;
|
||||
|
||||
//Now define new tree-based associative containers
|
||||
//
|
||||
|
||||
//AVLTree based set container
|
||||
typedef set<int, std::less<int>, new_allocator<int>, AVLTree> AvlSet;
|
||||
|
||||
//AVLTree based set container without size optimization
|
||||
typedef set<int, std::less<int>, new_allocator<int>, AVLTreeNoSizeOpt> AvlSetNoSizeOpt;
|
||||
|
||||
//Splay tree based multiset container
|
||||
typedef multiset<int, std::less<int>, new_allocator<int>, SplayTree> SplayMultiset;
|
||||
|
||||
//Use them
|
||||
//
|
||||
AvlSet avl_set;
|
||||
avl_set.insert(0);
|
||||
assert(avl_set.find(0) != avl_set.end());
|
||||
|
||||
AvlSetNoSizeOpt avl_set_no_szopt;
|
||||
avl_set_no_szopt.insert(1);
|
||||
avl_set_no_szopt.insert(1);
|
||||
assert(avl_set_no_szopt.count(1) == 1);
|
||||
|
||||
SplayMultiset splay_mset;
|
||||
splay_mset.insert(2);
|
||||
splay_mset.insert(2);
|
||||
assert(splay_mset.count(2) == 2);
|
||||
return 0;
|
||||
}
|
||||
//]
|
||||
|
||||
@@ -20,6 +20,10 @@ int main ()
|
||||
{
|
||||
using namespace boost::container;
|
||||
|
||||
//--------------------------------------------
|
||||
// 'stored_size' option
|
||||
//--------------------------------------------
|
||||
|
||||
//This option specifies that a vector that will use "unsigned char" as
|
||||
//the type to store capacity or size internally.
|
||||
typedef vector_options< stored_size<unsigned char> >::type size_option_t;
|
||||
@@ -43,6 +47,10 @@ int main ()
|
||||
|
||||
assert(exception_thrown == true);
|
||||
|
||||
//--------------------------------------------
|
||||
// 'growth_factor' option
|
||||
//--------------------------------------------
|
||||
|
||||
//This option specifies that a vector will increase its capacity 50%
|
||||
//each time the previous capacity was exhausted.
|
||||
typedef vector_options< growth_factor<growth_factor_50> >::type growth_50_option_t;
|
||||
|
||||
Reference in New Issue
Block a user