3 ms·
If I were doing this, I would accept one more C++-ism and implement a user-defined string literal, so one could do: "Some text"_s8 The underlying mechanis
by amluto 2y ago
If I were doing this, I would accept one more C++-ism and implement a user-defined string literal, so one could do:
"Some text"_s8
The underlying mechanism is even polite enough to supply a length without a horrible array template hack. (A somewhat unusual case where the C mechanism is a complete fail, the older C++ mechanism works but is incredibly ugly, and the newer C++ mechanism is actually straightforward and comprehensible.)
https://en.cppreference.com/w/cpp/language/user_literal https://en.cppreference.com/w/cpp/language/user_literal
- o11c 2y agoUDLs have one other huge benefit: you're far less likely to accidentally write a use-after-free, since otherwise there's no way to distinguish between being passed a string literal and being passed some other random char array. Between UDLs, a little CRTP to provide the same API across a set of classes, and `#pragma GCC poison`ing half the C library, I found it very easy to completely eliminate all legacy string-handling code in a codebase.