Are you using them?
A Recap on User Defined Literals
by Jonathan Boccara
From the article:
User defined literals were introduced in C++11, evolved in C++14 and C++17, and are a nice way to write more expressive code.
The general idea behind user defined literals is that they allow to write a value and tack on a term describing what this value represents. For example:
auto const quantity = 42_bottles_of_water;In this expression, 42 is the value and _bottles_of_water is the user defined suffix. The expression as a whole is a user defined literal.
A common usage of user defined literals is to represent units, but they can also be used to add meaning to values in more general contexts.
Here is how to write user defined literals in C++11, C++14 and C++17...
Add a Comment
Comments are closed.