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