This is an example of how to use a STL map container of which key is STL string.
#include <iostream>
#include <boost/container/string.hpp>
#include <boost/container/map.hpp>
using persistent_string =
boost::container::basic_string<char, std::char_traits<char>,
void string_int_map() {
using value_type = std::pair<const persistent_string,
int>;
using string_int_map =
boost::container::map<persistent_string, int, std::less<>,
{
auto pmap =
manager.construct<string_int_map>(
"string-int-map")(
pmap->insert(
value_type(persistent_string(
"zero",
manager.get_allocator<>()), 0));
(*pmap)[persistent_string(
"one",
manager.get_allocator<>())] = 1;
}
{
auto pmap =
manager.find<string_int_map>(
"string-int-map").first;
std::cout << pmap->at(persistent_string(
"zero",
manager.get_allocator<>()))
<< std::endl;
std::cout << pmap->at(persistent_string(
"one",
manager.get_allocator<>()))
<< std::endl;
}
}
void int_string_map() {
using value_type = std::pair<const int,
persistent_string>;
std::less<>, map_allocator_type>;
{
auto pmap =
manager.construct<int_string_map>(
"int-string-map")(
pmap->insert(
value_type(0, persistent_string(
"zero",
manager.get_allocator<>())));
(*pmap)[1] = persistent_string(
"one",
manager.get_allocator<>());
(*pmap)[2].push_back('t');
(*pmap)[2].push_back('w');
(*pmap)[2].push_back('o');
}
{
auto pmap =
manager.find<int_string_map>(
"int-string-map").first;
std::cout << pmap->at(0) << std::endl;
std::cout << pmap->at(1) << std::endl;
std::cout << pmap->at(2) << std::endl;
}
}
string_int_map();
int_string_map();
return 0;
}
int main()
Definition: jgraph.cpp:24