logoalt Hacker News

spacechild1 • today at 4:16 AM • 0 replies • view on HN

> What does behave like a std::string/std::vector but is not std::string/std::vector, respectively?

`std::span` works with all vector/array-like types: `std::vector`, `std::array`, C-arrays and third-party vector/array types.

Similarly, `std::string_view` works with `std::string`, C-strings and third-party string types.

> so that the autovectorization can kick in

It's not even about vectorization. Often you just have a function that takes a string-like or array-like thing, but you don't care about the exact container. Yes, you could make the argument a template (and constrain it with concepts), but then you have to put everything in headers.