Closed demozon closed 2 months ago
You can "extract" elements as follows:
#include <boost/unordered/concurrent_flat_map.hpp>
#include <cassert>
#include <optional>
int main()
{
using map = boost::concurrent_flat_map<int, int>;
using value_type = map::value_type;
map m = {{1, 2}};
std::optional<value_type> o;
m.erase_if(1, [&](value_type& x) {
o.emplace(std::move(x));
return true;
});
assert(o->first == 1);
assert(o->second == 2);
}
Extraction proper (without incurring any move construction) is not possible as boost::concurrent_flat_(map|set)
are not node-based. In Boost 1.87, boost::concurrent_node_(map|set)
will be provided with actual extract
capabilities, but bear in mind that these containers are generally slower than their flat counterparts.
That does do the trick, actually. Just need a const_cast in my case, since I'm using a set.
There exists a workaround
Hi,
Is it feasible to add a function for extracting elements (perhaps only by key) that takes a function as an additional argument? Or perhaps add an additional overload to erase?
E.g. something like
template
void extract(const key_type& k, F f);
My usecase is that I have an issue where I have an object that tries to delete itself.