4 ms·
`std::string_view` is essentially something like this: struct string_view { char *data; size_t length; } It is a pointer to a subset of an e
by gravypod 5y ago
`std::string_view` is essentially something like this:
struct string_view {
char *data;
size_t length;
}
It is a pointer to a subset of an existing string. It has all of the existing features of `std::string` but passing it around is zero copy. As long as the original memory allocation exists your `string_view`s are still valid. Also, it has an implicit constructor from `const std::string` and `const char #` allowing you you define a single function like `Thing ParseThing(std::string_view line)` and accept `char #` and `std::string` as an input.
More examples are here: https://abseil.io/tips/1 https://abseil.io/tips/1
# -> *. HN formats bad
- Arnavion 5y ago\* (backslash asterisk) will escape the asterisk. >Also, it has an implicit constructor from `const std::string` and `const char *` allowing you you define a single function like `Thing ParseThing(std::string_view line)` and accept `char *` and `std::string` as an input.