2 ms·
Exactly, thinking about things in terms of their implementations is usually not a good way to actually understand what that thing is. By arguing that std::strin
by Maxatar 2y ago
Exactly, thinking about things in terms of their implementations is usually not a good way to actually understand what that thing is. By arguing that std::string is just the struct itself, which consists of who knows what... you fail to appreciate the actual semantics of std::string and how those semantics are really what defines the std::string.
std::string_view also has implementation details that in principle could be similar to std::string, it's a pointer with a size, but the semantics of std::string_view are very different from the semantics of std::string.
And that's the crux of the issue, it's better to understand classes in terms of their semantics, how they operate, rather than their implementations. Implementations can change, and two very separate things can have the same or very similar implementations.
A std::string is not just some pointers and some record keeping data; a std::string is best understood as a class used to own and manage a sequence of characters with the various operations that one would expect for such management. A std::string_view is non-owning, read-only variation of such a class that operates on an existing sequence of characters.
How these are implemented and their structural details is not really what's important, it's how someone is expected to use them and what can be done with them that counts.
- Asraelite 2y agoMy original comment was just saying that it's useful to point out to people that the concrete representation of a string in memory is a struct when relevant, since some people might not realize that. I'm not claiming anything about the best way to think about it overall. > How these are implemented and their structural details is not really what's important Usually this isn't important, unless you're talking about low level details impacting performance, which is exactly what the article is about.
- epcoa 2y ago> Usually this isn't important, unless you're talking about low level details impacting performance, And if you’re going down that path, the string may not have a pointer at all. “A string value is not the string content itself”, but in most cases it is if the string is short enough, implementation dependent disclaimer and all that.