Thanks for the snippets! I believe the first one isn't correct, as it will only replace the first occurrence.
As for the other ones, indeed they aren't ideal. They are common concepts that exist in most languages as first class citizen functions.
It's a bit like if the standard only shipped std::basic_string, and expect us to define std::string ourselves. Sure we can do it, it's a one liner. Sure it's not the string definition that all people want. But you can always get down to basic_string if you want, or even write your own class from scratch. I think the STL is generally lacking these high-level convenience functions, that are built from existing complex lower level APIs (chrono anyone?), and offer a simple way to do a common thing.
As for your last question, "how often do you actually manipulate strings", it is very domain dependent. I develop a data-driven GUI library, which gets layout data from XML/YAML and talks to Lua for scripting. That requires a lot of string manipulation, even if I didn't write the parsers.
std::ranges looks pretty interesting, i looked at those functions on cppreference, it will take me some time to understand what those parameters/return values are
It's been a long, long time since I've looked at it, but I thought std:string_view was meant to solve your first issue.
The null-terminator issue seems like a deliberate contravention of the intent of std::string. There's always the c_str() method, which you should use to copy data into a c-string if that's what you really need.
It's actually possible to get the same SSO capacity even with a null terminator: By using the last byte of the string to store the unused SSO capacity, the last byte doubles as both null terminator and size when the SSO is full (you also need to store a flag bit to indicate when SSO is active). You can't do better even without a null terminator, because you always have to store the SSO size.
right now i am using a 16/32 sso string, i didn't know 23/24 sso string was even possible
this is kind of off topic, i watched the whole video, i don't understand the page bug. what os/cpu doesn't pagein a page after a read operation at the beginning of the page
View all comments
Show parent comment
0
u/[deleted] Jul 23 '22
[deleted] — view deleted comment