Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::text_encoding::literal

      From cppreference.com
      <cpp‎ |text‎ |text encoding
       
       
       
       
      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

      [edit]Parameters

      (none)

      [edit]Return value

      The object holding the representation of the ordinary literal encoding.

      [edit]Notes

      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.

      [edit]Example

      This example demonstrates the assertion that the ordinary literal encoding should be UTF-8.

      Run this code
      #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}";}
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/text/text_encoding/literal&oldid=179082"

      [8]ページ先頭

      ©2009-2026 Movatter.jp