Sync from upstream.

This commit is contained in:
Rene Rivera
2024-06-02 23:26:49 -05:00
5 changed files with 72 additions and 12 deletions

View File

@@ -43,7 +43,6 @@
#include <boost/intrusive/detail/minimal_pair_header.hpp> //pair
#include <boost/move/make_unique.hpp>
#include <boost/move/iterator.hpp>
#include <boost/move/adl_move_swap.hpp>
#include <boost/move/detail/iterator_to_raw_pointer.hpp>

View File

@@ -415,9 +415,7 @@ class small_vector_base
{}
void prot_shrink_to_fit_small(const size_type small_capacity)
{
this->base_type::prot_shrink_to_fit_small(this->internal_storage(), small_capacity);
}
{ this->base_type::prot_shrink_to_fit_small(this->internal_storage(), small_capacity); }
using base_type::protected_set_size;
@@ -667,9 +665,7 @@ class small_vector
{ return this->base_type::prot_swap(other, static_capacity); }
inline void shrink_to_fit()
{
this->base_type::prot_shrink_to_fit_small(this->internal_capacity());
}
{ this->base_type::prot_shrink_to_fit_small(this->internal_capacity()); }
};
}}

View File

@@ -2891,11 +2891,11 @@ private:
);
boost::container::destroy_alloc_n(this->get_stored_allocator(), oldbuf, sz);
this->m_holder.m_start = small_buffer;
this->m_holder.set_stored_capacity(small_capacity);
if (BOOST_LIKELY(!!this->m_holder.m_start))
this->m_holder.deallocate(this->m_holder.m_start, cp);
this->m_holder.m_start = small_buffer;
this->m_holder.set_stored_capacity(small_capacity);
}
else if (sz < cp) {
this->priv_move_to_new_buffer(sz, alloc_version());

View File

@@ -318,7 +318,7 @@ int map_test_range()
::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] + 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>
(&aux_vect2[0], &aux_vect2[0] + MaxElem, typename MyStdMap::key_compare());
if(!CheckEqualContainers(*pboostmultimap, *pstdmultimap)) return 1;

View File

@@ -34,6 +34,71 @@ struct alloc_propagate_base<boost_container_small_vector>
}}} //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()
{
typedef boost::container::small_vector_base<int> smb_t;
@@ -452,7 +517,7 @@ int main()
////////////////////////////////////
// Small vector base
////////////////////////////////////
if (!test_small_vector_base_test()){
if (!test_small_vector_shrink_to_fit()){
return 1;
}