Namespaces
Variants

std::text_encoding:: literal

From cppreference.net
static consteval text_encoding literal ( ) noexcept ;
(C++26부터)

text_encoding 객체를 새로 생성하며, 이는 일반 문자 리터럴 인코딩 을 나타냅니다. 이것은 일반 문자나 문자열 리터럴(예: "This is literal" )에 적용되는 문자 인코딩을 결정하는 데 사용됩니다.

이 함수는 CHAR_BIT 8 이 아닌 경우 삭제됩니다.

목차

매개변수

(없음)

반환값

일반 리터럴 인코딩의 표현을 보유하는 객체입니다.

참고 사항

이 함수는 컴파일러별 내장 매크로를 사용하여 text_encoding 을 구성함으로써 구현할 수 있습니다. 예를 들어 Clang의 __clang_literal_encoding__ 또는 GCC의 __GNUC_EXECUTION_CHARSET_NAME 같은 매크로들을 사용할 수 있습니다. 이러한 매크로들은 컴파일 타임에 알려지며, 사용되는 narrow 실행 문자 집합의 이름을 포함하는 narrow 문자열 리터럴로 확장됩니다(일반적인 리터럴 인코딩).

literal ( ) 에 의해 반환되는 값은 GCC나 Clang의 -fexec-charset= encoding-name 또는 MSVC의 /execution-charset: encoding-name 와 같은 컴파일러 옵션에 따라 달라질 수 있습니다.

예제

이 예제는 일반 리터럴 인코딩이 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-8
    constexpr char green_heart[] = "\N{GREEN HEART}";
    // this prefixed string literal is always encoded as UTF-8 regardless of the
    // literal encoding
    constexpr char8_t green_heart_u8[] = u8"\N{GREEN HEART}";
}