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

Function greeting

test/snippets.cpp:263–279  ·  view source on GitHub ↗

tag::snippet_strings_5[]

Source from the content-addressed store, hash-verified

261
262// tag::snippet_strings_5[]
263string greeting( string_view first_name, string_view last_name )
264{
265 const char hello[] = "Hello, ";
266 const std::size_t sz = first_name.size() + last_name.size() + sizeof(hello) + 1;
267
268 string js;
269 js.reserve(sz);
270
271 char* p = std::copy( hello, hello + sizeof(hello) - 1, js.data() );
272 p = std::copy( first_name.begin(), first_name.end(), p );
273 *p++ = ' ';
274 p = std::copy( last_name.begin(), last_name.end(), p );
275 *p++ = '!';
276
277 js.grow( sz );
278 return js;
279}
280// end::snippet_strings_5[]
281
282void

Callers 1

usingStringsFunction · 0.85

Calls 6

sizeMethod · 0.45
reserveMethod · 0.45
dataMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
growMethod · 0.45

Tested by

no test coverage detected