| Localization library | |||||||||||||||||||||||||
| Regular expressions library(C++11) | |||||||||||||||||||||||||
| Formatting library(C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Member functions | ||||
| Creation | ||||
text_encoding::literal | ||||
| Observers | ||||
| Helpers | ||||
| Non-member functions | ||||
| Member types | ||||
| Helper classes | ||||
static consteval text_encoding literal()noexcept; | (since C++26) | |
Constructs a newtext_encoding object representing theordinary character literal encoding. It is used to determine the character encoding applied to ordinary character or string literals (e.g."This is literal").
This function is deleted unless theCHAR_BIT is8.
Contents |
(none)
The object holding the representation of the ordinary literal encoding.
This function can be implemented by constructingtext_encoding with compiler-specific builtin macros such as__clang_literal_encoding__ from Clang, or__GNUC_EXECUTION_CHARSET_NAME from GCC. These macros, which are known at compile-time, expand to a narrow string literal containing the name of the narrow execution character set used (ordinary literal encoding).
The value returned byliteral() may depend on compiler options such as-fexec-charset=encoding-name in GCC or Clang or/execution-charset:encoding-name in MSVC.
This example demonstrates the assertion that the ordinary literal encoding should be UTF-8.
#include <text_encoding> static_assert(std::text_encoding::literal()== std::text_encoding::UTF8); int main(){// if the literal encoding is UTF-8, then this unprefixed string literal is// encoded as UTF-8constexprchar green_heart[]="\N{GREEN HEART}"; // this prefixed string literal is always encoded as UTF-8 regardless of the// literal encodingconstexpr char8_t green_heart_u8[]= u8"\N{GREEN HEART}";}