#include <boost/container/pmr/vector.hpp>
#include <boost/container/pmr/string.hpp>
class ShoppingList
{
boost::container::pmr::vector_of
<boost::container::pmr::string>::type m_strvec;
public:
typedef boost::container::pmr::memory_resource* allocator_type;
explicit ShoppingList(allocator_type alloc = 0)
: m_strvec(alloc) {}
ShoppingList(const ShoppingList& other)
: m_strvec(other.m_strvec) {}
ShoppingList(const ShoppingList& other, allocator_type a)
: m_strvec(other.m_strvec, a) {}
allocator_type get_allocator() const
{ return m_strvec.get_allocator().resource(); }
void add_item(const char *item)
{ m_strvec.emplace_back(item); }
};
#include <cassert>
#include <boost/container/pmr/list.hpp>
#include <boost/container/pmr/monotonic_buffer_resource.hpp>
void processShoppingList(const ShoppingList&)
{ }
int main()
{
using namespace boost::container;
pmr::list_of<ShoppingList>::type folder; {
char buffer[1024];
pmr::monotonic_buffer_resource buf_rsrc(&buffer, 1024);
ShoppingList temporaryShoppingList(&buf_rsrc);
assert(&buf_rsrc == temporaryShoppingList.get_allocator());
temporaryShoppingList.add_item("salt");
temporaryShoppingList.add_item("pepper");
processShoppingList(temporaryShoppingList);
folder.push_back(temporaryShoppingList);
assert(pmr::get_default_resource() == folder.back().get_allocator());
}
return 0;
}