You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the allocator aliases such as memory::unordered_map use directly memory::std_allocator<>.
However, if one wants to nest unordered_maps for example, using the rather intuitive memory::unordered_map<K1, memory::unordered_map<K2, V2>> leads to headaches since the [] operator requires the default constructor for the K2, V2 map to be called, which can't happen since we need to provide the allocator during creation.
Inside my code I've fixed this ('I've duplicated too much code' in this case) using the following std::scoped_allocator_adapter:
using memory_pool_collection = memory::memory_pool_collection<
memory::node_pool,
memory::log2_buckets>;
using unordered_set_int = std::unordered_set<int, std::hash<int>, std::equal_to<>,
memory::std_allocator<int, memory_pool_collection, memory::default_mutex>>;
using unordered_map_int_si = std::unordered_map<int, unordered_set_int, std::hash<int>, std::equal_to<int>,
std::scoped_allocator_adaptor<
memory::std_allocator<std::pair<const int, unordered_set_int>, memory_pool_collection, memory::default_mutex>>>;
My proposal is that inside the container aliases header we could add something like
This way the outermost allocator could be a scoped one, while the inside ones would still keep on being the normal versions. What I'm not entirely sure for now is if nesting 3 containers (so, map, in a map, in a map), requires the second container to be scoped or not.
The text was updated successfully, but these errors were encountered:
Currently the allocator aliases such as memory::unordered_map use directly memory::std_allocator<>.
However, if one wants to nest unordered_maps for example, using the rather intuitive memory::unordered_map<K1, memory::unordered_map<K2, V2>> leads to headaches since the [] operator requires the default constructor for the K2, V2 map to be called, which can't happen since we need to provide the allocator during creation.
Inside my code I've fixed this ('I've duplicated too much code' in this case) using the following std::scoped_allocator_adapter:
My proposal is that inside the container aliases header we could add something like
This way the outermost allocator could be a scoped one, while the inside ones would still keep on being the normal versions. What I'm not entirely sure for now is if nesting 3 containers (so, map, in a map, in a map), requires the second container to be scoped or not.
The text was updated successfully, but these errors were encountered: