According to the description in cppreference.com:
The class template
basic_string_view
describes an object that can refer to a constant contiguous sequence ofchar
-like objects with the first element of the sequence at position zero.
However, it could be useful to use that class template with non-const char
pointers, for example to write to a null-terminated byte string using the standard algorithms. For example, imaging an hypotetical std::editable_string_view
owning a char*
, one could write something like
void filler(char *str, std::size_t len, char c) {
std::editable_string_view sv(str, len);
std::fill(sv.begin(), sv.end(), c);
}
Are there reasons for std::basic_string_view
to support only const pointers?