5 ms·
This blew my mind. Mostly because I haven't come across this during 8 years of c++ use for professional/competitive programming.
by nikhilsimha 5y ago
This blew my mind. Mostly because I haven't come across this during 8 years of c++ use for professional/competitive programming.
- WalterBright 5y agoI've never seen anyone use these since they appeared in the spec decades ago. They're as pointless as trigraphs, which I've never seen in the wild either.
- jeffbee 5y agoEver seen a real use of `operator"" _X`, the C++11 feature that lets you declare a literal constant like this? int operator"" _km(unsigned long long); auto distance = 42_km; The breadth of crazy features in C++ is really huge, when you dig in.
- WalterBright 5y agoThe equivalent thing in D is, but without a special feature: template _km(ulong v) { enum _km = inKilometers(v); } auto distance = _km!42; It's used by the Sargon library to create a halffloat type: https://digitalmars.com/sargon/halffloat.html https://digitalmars.com/sargon/halffloat.html I haven't seen it used in C++, though my C++ experience post this feature is limited.
- pjmlp 5y agoAll the time, "A safer string"s Declares a std::string constant. While I agree C++ is huge, I doubt anyone would survive a Python, Java, C#, VB.NET, JavaScript, Typescript, Fortran, Ada, Common Lisp, COBOL, C pub quiz, based on the very latest language versions.
- tom_ 5y agohttps://github.com/nlohmann/json/blob/c215b77936591d4fe0aa0a1df737eb944b4ee38b/src/json.hpp#L1122 https://github.com/nlohmann/json/blob/c215b77936591d4fe0aa0a...
- WalterBright 5y agoCongratulations! There's one!
- jcelerier 5y agoOne thing is, for the longest time MSVC did not support them (against the spec like always) so they could not be used if you wanted cross-platform code.