Closed OHNOalan closed 2 months ago
The problem you're experiencing is due to the fact that boost::unordered_flat_map
requires that both its key and mapped types be move constructible, and std::atomic
types are not move (or even copy) constructible.
There's a number of ways you can work around this:
boost::unordered_node_map
, which does not have the move constructibility requirement (but is slower than boost::unordered_flat_map
).std::atomic
with a copyable substitute:#include <boost/unordered/unordered_flat_map.hpp>
#include <atomic>
struct copyable_atomic_int: std::atomic<int>
{
using super = std::atomic<int>;
using super::super;
copyable_atomic_int(const copyable_atomic_int& x): super{x.load()} {}
};
int main()
{
boost::unordered::unordered_flat_map<int, copyable_atomic_int> m;
m.try_emplace(1,0);
return 0;
}
Good luck with your project,
Thank you~
I encountered an error when trying to emplace an std::atomic value into a boost::unordered::unordered_flat_map. Here is a minimal reproducible example:
The above program throws an error when attempting to emplace an std::atomic value into the map. The compiler error message is as follows: