mirror of
https://github.com/boostorg/container.git
synced 2025-07-31 04:57:16 +02:00
Add shrink_to_fit tests to small_vector
This commit is contained in:
@ -318,7 +318,7 @@ int map_test_range()
|
|||||||
|
|
||||||
::boost::movelib::unique_ptr<MyBoostMultiMap> const pboostmultimap = ::boost::movelib::make_unique<MyBoostMultiMap>
|
::boost::movelib::unique_ptr<MyBoostMultiMap> const pboostmultimap = ::boost::movelib::make_unique<MyBoostMultiMap>
|
||||||
( boost::make_move_iterator(&aux_vect3[0])
|
( boost::make_move_iterator(&aux_vect3[0])
|
||||||
, boost::make_move_iterator(&aux_vect3[0] + MaxElem), typename MyBoostMap::allocator_type());
|
, boost::make_move_iterator(&aux_vect3[0] + MaxElem));
|
||||||
::boost::movelib::unique_ptr<MyStdMultiMap> const pstdmultimap = ::boost::movelib::make_unique<MyStdMultiMap>
|
::boost::movelib::unique_ptr<MyStdMultiMap> const pstdmultimap = ::boost::movelib::make_unique<MyStdMultiMap>
|
||||||
(&aux_vect2[0], &aux_vect2[0] + MaxElem, typename MyStdMap::key_compare());
|
(&aux_vect2[0], &aux_vect2[0] + MaxElem, typename MyStdMap::key_compare());
|
||||||
if(!CheckEqualContainers(*pboostmultimap, *pstdmultimap)) return 1;
|
if(!CheckEqualContainers(*pboostmultimap, *pstdmultimap)) return 1;
|
||||||
|
@ -34,6 +34,71 @@ struct alloc_propagate_base<boost_container_small_vector>
|
|||||||
|
|
||||||
}}} //namespace boost::container::test
|
}}} //namespace boost::container::test
|
||||||
|
|
||||||
|
|
||||||
|
bool test_small_vector_shrink_to_fit()
|
||||||
|
{
|
||||||
|
boost::container::small_vector<int, 5> sm5;
|
||||||
|
boost::container::vector<int> v;
|
||||||
|
sm5.push_back(1);
|
||||||
|
sm5.push_back(2);
|
||||||
|
sm5.push_back(3);
|
||||||
|
sm5.push_back(4);
|
||||||
|
sm5.push_back(5);
|
||||||
|
|
||||||
|
v.push_back(1);
|
||||||
|
v.push_back(2);
|
||||||
|
v.push_back(3);
|
||||||
|
v.push_back(4);
|
||||||
|
v.push_back(5);
|
||||||
|
|
||||||
|
if (!sm5.is_small())
|
||||||
|
return false;
|
||||||
|
if (!boost::container::algo_equal(sm5.begin(), sm5.end(), v.begin(), v.end()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//Shrinking a when internal storage is used is a no-op
|
||||||
|
sm5.shrink_to_fit();
|
||||||
|
|
||||||
|
if (!sm5.is_small())
|
||||||
|
return false;
|
||||||
|
if (!boost::container::algo_equal(sm5.begin(), sm5.end(), v.begin(), v.end()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//If dynamic memory is used, shrink_to_fit will move elements to the internal storage
|
||||||
|
sm5.push_back(6);
|
||||||
|
v.push_back(6);
|
||||||
|
if (sm5.is_small())
|
||||||
|
return false;
|
||||||
|
sm5.pop_back();
|
||||||
|
v.pop_back();
|
||||||
|
if (sm5.is_small())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
sm5.shrink_to_fit();
|
||||||
|
if (!sm5.is_small())
|
||||||
|
return false;
|
||||||
|
if (!boost::container::algo_equal(sm5.begin(), sm5.end(), v.begin(), v.end()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//If dynamic memory is used, and size is zero the dynamic storage is deallocated
|
||||||
|
sm5.push_back(6);
|
||||||
|
v.push_back(6);
|
||||||
|
if (sm5.is_small())
|
||||||
|
return false;
|
||||||
|
sm5.clear();
|
||||||
|
v.clear();
|
||||||
|
if (sm5.is_small())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
sm5.shrink_to_fit();
|
||||||
|
if (!sm5.is_small())
|
||||||
|
return false;
|
||||||
|
if (!boost::container::algo_equal(sm5.begin(), sm5.end(), v.begin(), v.end()))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool test_small_vector_base_test()
|
bool test_small_vector_base_test()
|
||||||
{
|
{
|
||||||
typedef boost::container::small_vector_base<int> smb_t;
|
typedef boost::container::small_vector_base<int> smb_t;
|
||||||
@ -452,7 +517,7 @@ int main()
|
|||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
// Small vector base
|
// Small vector base
|
||||||
////////////////////////////////////
|
////////////////////////////////////
|
||||||
if (!test_small_vector_base_test()){
|
if (!test_small_vector_shrink_to_fit()){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user