I'm trying to use std::string_view
as much as I can to wrap C-string, however, whenever the C-string I'm wrapping is dynamically allocated, I rely on this pattern:
char *cs = get_c_string();
std::string s(cs);
free(cs);
which is a waste of time because it involves 1 allocation, 1 copy and 1 deallocation.
Is there a way to do this better ? Or do I need to write my own string_view
wrapper ?