User defined literals are a new feature in C++ since C++11. In it’s simplest form, it allows the programmer to use a suffix on any literal in the code. The most obvious example is to use user defined literals to strongly convert time and make it possible to add weeks, days and seconds without using cumbersome libraries like boost::units and similar.
But you have to remember to stick to the rules. In Visual Studio (2015 preview) you’ll get C4455 if you try to define an user defined literal without a leading underscore. That is very good. However, that’s the only violation Visual Studio will report (at least with 2015 preview).
// Not OK. C4455 long double operator "" w(long double value) { return value; } // OK long double operator "" _w(long double value) { return value; } // Not OK. Underscore and an upper case letter are reserved. long double operator "" _E(long double value) { return value; } // Not OK. Double underscores are reserved. long double operator "" __w(long double value) { return value; }
If you include
auto seconds = 1.2s + 2h + 6min; // seconds = 7561.5000000000000 seconds
Pretty neat.