You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The difference between the two is that reference references an object of type std::string which is defined to contain a unique buffer for its characters, while std::string_view describes a section of existing memory containing the characters. The previous arguments decleration style makes passing substring and static C-string to a function include an additional and (99% of the time) unneccessary step of allocating new buffer for and copying the characters to it, std::string_view argument does not have this flaw as it is capable of describing these sections of memory without copying them.
The text was updated successfully, but these errors were encountered:
This is true for even static constexpr std::string in C++20 when an address is required such as when calling c_str() (compiler cannot optimize it, buffer must be unique in this case). So string_view is recommended for static strings as well.
For constexpr strings plain old char array can do its job. It's usually not a problem to convert it to string_view on the fly. It feels however we may be missing some kind of nts_view to preserve a null-terminator.
The difference between the two is that reference references an object of type std::string which is defined to contain a unique buffer for its characters, while std::string_view describes a section of existing memory containing the characters. The previous arguments decleration style makes passing substring and static C-string to a function include an additional and (99% of the time) unneccessary step of allocating new buffer for and copying the characters to it, std::string_view argument does not have this flaw as it is capable of describing these sections of memory without copying them.
The text was updated successfully, but these errors were encountered: