std::text_encoding::literal
From cppreference.com
< cpp | text | text encoding
| static consteval text_encoding literal() noexcept; |
(C++26以降) | |
通常の文字リテラルエンコーディング(ordinary character literal encoding)を表す新しいtext_encodingオブジェクトを構築します。これは、通常の文字または文字列リテラル(例:"This is literal")に適用される文字エンコーディングを決定するために使用されます。
この関数は、CHAR_BIT が 8 でない限り、削除されます。
目次 |
[編集] パラメータ
(なし)
[編集] 戻り値
通常の文字リテラルエンコーディングの表現を保持するオブジェクト。
[編集] 注記
この関数は、Clangの__clang_literal_encoding__やGCCの__GNUC_EXECUTION_CHARSET_NAMEのようなコンパイラ固有の組み込みマクロを使用してtext_encodingを構築することで実装される場合があります。これらのマクロはコンパイル時に認識され、ナロー実行文字セット(通常の文字リテラルエンコーディング)の名前を含むナロー文字列リテラルに展開されます。
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}"; }