I assume nobody ever uses std::string_view::max_size() outside of
testing. However, we should still return a value that is based on
something with a reasonable rationale. Previously, we would forget
to take into account the size of the character type stored in the
string. This patch factors both that and the size of the string_view
itself into account.
Thanks to @mclow.lists for pointing out this issue.
(1) This seems unnecessarily fiddly; I don't really see anything wrong with the original.
(2) If we're going to do this, let's add a line break somewhere.
(3) Since sv.size() cannot physically return anything bigger than PTRDIFF_MAX, you probably want to use ptrdiff_t instead of size_type here... or maybe return std::min(PTRDIFF_MAX, SIZE_MAX / sizeof(value_type))? But again, this is needlessly fiddly and I see nothing wrong with just returning SIZE_MAX unconditionally. Literally nobody should ever be calling this method.
Do any of the other methods (e.g. the constructor) need to do something special to preserve the postcondition that sv.size() <= sv.max_size()? Before this change, the postcondition was vacuously true; now, it could conceivably be false, and maybe we need to check for that?