2 ms·
Ever 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
by jeffbee 6y ago
Ever 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 6y 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 6y 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.