Site icon Learn C++

What Are The Standard User-Defined Literals In C++14?

What Are The Standard User Defined Literals In C++14

C++11 introduced new forms of literals using modified syntax and semantics to provide User-Defined Literals (UDL) also known as Extensible Literals. While there was the ability to use them the standard library did not use any of them. In C++14, the commission added some standard literals. In this post, we explain user-defined literals operators and we explain some of these standard literals added in C++14.

What are the user defined literal operators in C++?

C++11 introduced new forms of literals using modified syntax and semantics in order to provide User-Defined Literals (UDL) also known as Extensible Literals. Using user-defined literals, user-defined classes can provide new literal syntax and they can be used with the operator "" to combine values with conversion operators. Here below, we explain how to use user-defined literals in C++.

What are the standard user-defined literals in C++14?

In C++14, we have some standard user-defined literal operators that comes with standard library. These are literals for basic strings, for chrono types, and for complex number types.

We can access to these operators by:

C++14 adds the following standard literals below,

For the string types there is an operator”” s() for basic string,

here how we can use it with auto,

[crayon-663c493938e13339406610/]

Suffixes for std::chrono::duration values,

here how we can use them with auto,

[crayon-663c493938e1a316035982/]

Suffixes for complex number literals,

here how we can use them with auto,

[crayon-663c493938e1d587093876/]

there are more definitions.

Is there a full example of how to use standard user-defined literals in C++14?

Here is a full example about standard user-defined literals in C++.

[crayon-663c493938e1e484734807/]

For more information about the standard user-defined literals, please see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3402.pdf

C++ Builder is the easiest and fastest C and C++ compiler and IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.

Exit mobile version