Chapter 2
Working with User-Defined Literals (UDLs)
IN THIS CHAPTER
Considering the needs and uses for UDLs
Using the UDL features of the Standard Library
Developing custom UDLs
Previous chapters have discussed literals as a kind of constant. For example, in the expression X = 5
, the number 5
is a literal constant. The constant X
stands in for the value 5
in application code. Using a literal enables you to create code that states the use of a value clearly, rather than having code that is filled with mystery values that no one can figure out. In addition, using literals lets you change constant values in one place, rather than in each place they’re needed in an application.
Up to this point, you have used every other kind of literal constant in the various examples except for User-Defined Literals (UDLs). Unlike other kinds of literal constants, a UDL isn’t defined as part of the C++ compiler — you create UDLs as needed to make your code more readable and easier to manage. In some cases, UDLs come with the libraries you use in C++, such as the Standard Library. This chapter does discuss UDLs that come as part of the Standard Library, but it also looks at how you’d create your ...
Get C++ All-in-One For Dummies, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.