MCPcopy Create free account
hub / github.com/boostorg/json / set1

Function set1

test/doc_uses_allocator.cpp:22–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20//----------------------------------------------------------
21
22static void set1() {
23
24//----------------------------------------------------------
25{
26// tag::doc_uses_allocator_1[]
27// We want to use this resource for all the containers
28monotonic_resource mr;
29
30// Declare a vector of JSON values
31std::vector< value, boost::container::pmr::polymorphic_allocator< value > > v( &mr );
32
33// The polymorphic allocator will use our resource
34assert( v.get_allocator().resource() == &mr );
35
36// Add a string to the vector
37v.emplace_back( "boost" );
38
39// The vector propagates the memory resource to the string
40assert( v[0].storage().get() == &mr );
41// end::doc_uses_allocator_1[]
42}
43//----------------------------------------------------------
44{
45// tag::doc_uses_allocator_2[]
46// This vector will use the default memory resource
47std::vector< value, boost::container::pmr::polymorphic_allocator < value > > v;
48
49// This value will same memory resource as the vector
50value jv( v.get_allocator() );
51
52// However, ownership is not transferred,
53assert( ! jv.storage().is_shared() );
54
55// and deallocate is never null
56assert( ! jv.storage().is_deallocate_trivial() );
57// end::doc_uses_allocator_2[]
58}
59//----------------------------------------------------------
60
61} // set1
62
63//----------------------------------------------------------
64

Callers

nothing calls this directly

Calls 4

is_sharedMethod · 0.80
is_deallocate_trivialMethod · 0.80
get_allocatorMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected