Add erase_if for set/flat_set

This commit is contained in:
Ion Gaztañaga
2025-11-01 11:49:49 +01:00
parent 5fea200894
commit a7873e975d
4 changed files with 109 additions and 0 deletions

View File

@@ -12,6 +12,7 @@
#define BOOST_CONTAINER_TEST_SET_TEST_HEADER
#include <boost/container/detail/config_begin.hpp>
#include <boost/container/detail/compare_functors.hpp>
#include "check_equal_containers.hpp"
#include "print_container.hpp"
#include "movable_int.hpp"
@@ -823,6 +824,54 @@ int set_test ()
if(!CheckEqualContainers(boostmultiset, stdmultiset)) return 1;
}
{ //erase_if
boostset.clear();
boostmultiset.clear();
stdset.clear();
stdmultiset.clear();
{
IntType aux_vect[(std::size_t)MaxElem];
IntType aux_vect2[(std::size_t)MaxElem];
IntType aux_vect3[(std::size_t)MaxElem];
for(int i = 0; i < MaxElem; ++i){
aux_vect[i] = i;
aux_vect2[i] = i;
aux_vect3[i] = i;
}
boostset. insert(boost::make_move_iterator(&aux_vect[0]), boost::make_move_iterator(&aux_vect[0] + MaxElem));
boostmultiset.insert(boost::make_move_iterator(&aux_vect2[0]), boost::make_move_iterator(&aux_vect2[0] + MaxElem));
boostmultiset.insert(boost::make_move_iterator(&aux_vect3[0]), boost::make_move_iterator(&aux_vect3[0] + MaxElem));
}
for(int i = 0; i < MaxElem; ++i){
stdset.insert(i);
stdmultiset.insert(i);
stdmultiset.insert(i);
}
for(int i = 0; i < MaxElem; ++i) {
//erase_if
const int setkey = (i + MaxElem/2) % MaxElem;
if (1 != erase_if(boostset, equal_to_value<int>(setkey)))
return 1;
if (0 != erase_if(boostset, equal_to_value<int>(setkey)))
return 1;
stdset.erase(setkey);
if(!test::CheckEqualContainers(boostset, stdset)) return false;
//erase_if
if (2 != erase_if(boostmultiset, equal_to_value<int>(setkey)))
return 1;
if (0 != erase_if(boostmultiset, equal_to_value<int>(setkey)))
return 1;
stdmultiset.erase(setkey);
if(!test::CheckEqualContainers(boostmultiset, stdmultiset)) return false;
}
}
if(set_test_copyable<MyBoostSet, MyStdSet, MyBoostMultiSet, MyStdMultiSet>
(dtl::bool_<boost::container::test::is_copyable<IntType>::value>())){
return 1;