This is an example of how to use a complex STL map container with Metall.
#include <iostream>
#include <boost/container/scoped_allocator.hpp>
#include <boost/container/string.hpp>
#include <boost/container/map.hpp>
namespace bc = boost::container;
template <typename allocator_type, typename new_type>
using rebind_alloc = typename std::allocator_traits<
allocator_type>::template rebind_alloc<new_type>;
using key_type = int;
template <typename _allocator_type>
struct mapped_type {
using allocator_type = _allocator_type;
bc::vector<int, rebind_alloc<_allocator_type, int>> vec;
bc::basic_string<char, std::char_traits<char>,
rebind_alloc<_allocator_type, char>>
str;
explicit mapped_type(const allocator_type &allocator)
: vec(allocator), str(allocator) {}
};
template <typename allocator_type>
using value_type = std::pair<const key_type, mapped_type<allocator_type>>;
template <typename base_allocator_type>
rebind_alloc<base_allocator_type, value_type<base_allocator_type>>>;
template <typename base_allocator_type>
using map_type =
boost::container::map<key_type, mapped_type<base_allocator_type>,
std::less<>, map_allocator_type<base_allocator_type>>;
using metall_map_type = map_type<metall::manager::allocator_type<std::byte>>;
{
auto pmap =
(*pmap)[0];
pmap->at(0).vec.push_back(0);
pmap->at(0).str = "hello, world 0";
pmap->try_emplace(1);
pmap->at(1).vec.push_back(1);
pmap->at(1).str = "hello, world 1";
}
{
auto pmap =
manager.find<metall_map_type>(
"map").first;
std::cout << pmap->at(0).vec[0] << std::endl;
std::cout << pmap->at(0).str << std::endl;
std::cout << pmap->at(1).vec[0] << std::endl;
std::cout << pmap->at(1).str << std::endl;
}
return 0;
}
int main()
Definition: jgraph.cpp:24