And the while loop shouldn't even run at all since front() never equals ' '.
And the while loop shouldn't even run at all since front() never equals ' '.
That is effectively what is happening internally. A string_view is morally a pointer/length pair; that pointer has to be initialized somehow.
> and even if it's just internally referencing the (static) string
It's not. The function call constructs a temporary std::string from the string literal, but once that is done the contents of the temporary are entirely independent from the string literal.
struct string_view { const char * ref; }
Where ref comes from the temporary string constructed via Sanitize("foobarbaz"). When that expression is done, the temporary string is destructed, leaving a dangling pointer.Possibly useful elaboration: https://quuxplusone.github.io/blog/2022/12/15/sophist/
In C++, where "reference" and "pointer" both have technical (jargon) meanings, you might still get away with calling string_view a "handle" (to a contiguous bunch of characters). See also https://quuxplusone.github.io/blog/2023/02/04/jargon-treadmi...