MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / copy_assignment

Function copy_assignment

examples/src/pmr_allocator_examples.cpp:99–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99void copy_assignment() // assignment
100{
101 char buffer[1024];
102 std::pmr::monotonic_buffer_resource pool{ std::data(buffer), std::size(buffer) };
103 std::pmr::polymorphic_allocator<char> alloc(&pool);
104
105 char buffer1[1024];
106 std::pmr::monotonic_buffer_resource pool1{ std::data(buffer1), std::size(buffer1) };
107 std::pmr::polymorphic_allocator<char> alloc1(&pool1);
108
109 jsoncons::pmr::json j{ "String too long for short string", alloc };
110 assert(j.is_string());
111 assert(j.get_allocator().resource() == &pool);
112
113 // copy long string to number
114 jsoncons::pmr::json j1{10};
115 j1 = j;
116 assert(j1.is_string());
117 assert(j1.get_allocator() == std::allocator_traits<std::pmr::polymorphic_allocator<char>>::
118 select_on_container_copy_construction(j.get_allocator()));
119 assert(j1.get_allocator() == std::pmr::polymorphic_allocator<char>{});
120
121 // copy long string to array
122 jsoncons::pmr::json j2{ jsoncons::json_array_arg, {1,2,3,4},
123 jsoncons::semantic_tag::none, alloc1};
124 j2 = j;
125 assert(j2.is_string());
126 assert(j2.get_allocator().resource() == &pool1);
127}
128
129void move_assignment() // assignment
130{

Callers 1

mainFunction · 0.70

Calls 3

sizeFunction · 0.85
is_stringMethod · 0.80
get_allocatorMethod · 0.45

Tested by

no test coverage detected