Namespaces
Variants

class property specifiers (since C++26)

From cppreference.net
C++ language
General topics
Flow control
Conditional execution statements
Iteration statements (loops)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications ( until C++17* )
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
Miscellaneous

クラスが 置換可能 ( replaceable_if_eligible )、 自明に再配置可能 ( trivially_relocatable_if_eligible )、またはクラスが 派生できない ( final ) ことを指定します。

目次

構文

クラスプロパティ指定子 はクラス定義の先頭、クラス名の直後に現れ、クラス宣言内では現れることはできません。

class-key attr  (任意) class-head-name class-prop-specifier-seq  (任意) base-clause  (任意)
class-prop-specifier-seq - 1つ以上の class-prop-specifier からなるが、各々は最大1回のみ出現可能
class-prop-specifier - final replaceable_if_eligible および trivially_relocatable_if_eligible のいずれか

C++26より前では、 class-prop-specifier-seq  (optional) の代わりに class-virt-specifier  (optional) があり、 final specifier (C++11以降) final のみが許可されていました。

説明

final replaceable_if_eligible および trivially_relocatable_if_eligible は、クラスヘッドで使用された場合に特別な意味を持つ識別子です。他の文脈では予約語ではなく、オブジェクトや関数の命名に使用できます。

final 指定子

final は、このクラスが他のクラス定義の base-specifier-list に現れてはならないことを指定します(つまり、派生クラスを作成できません)。それ以外の場合、プログラムは不適格となります(コンパイル時エラーが発生します)。 final union 定義でも使用できますが、その場合 std::is_final の結果に影響を与える以外は) (C++14以降) 効果はありません。これはunionが派生できないためです。

replaceable_if_eligible 指定子

replaceable_if_eligible は、このクラスが 置換可能  である場合に、 置換の対象となる資格がある  ことを指定します。

trivially_relocatable_if_eligible 指定子

trivially_relocatable_if_eligible は、このクラスが 自明に再配置可能 である場合に、 自明な再配置の対象となる資格がある ことを指定します。

置換可能性

クラス C は、それが 置換適格 であり、かつ以下のいずれかの条件を満たす場合、 置換可能 です:

交換対象の条件

クラス C は、以下のいずれかの条件に該当しない限り 置換可能 です:

自明な再配置可能性

クラスは、以下のいずれかの条件を満たす場合に 自明に再配置可能 (trivially relocatable)  となります: 自明な再配置の適格性 (eligible for trivial relocation)  を満たし、かつ:

自明な再配置の適格性

クラスは、以下のいずれかを持つ場合を除き、 自明な再配置が可能 です:

ただし、多態的なクラス型の1つ以上のサブオブジェクトを持つ、それ以外の条件を満たす union 自明な再配置の対象となるかどうか は実装定義である。

デフォルトの移動可能性

クラス C default movable であるための条件は以下のすべてを満たすことです:

  • C 型の direct-initializing による xvalue からのオブジェクト初期化におけるオーバーロード解決は、 C の直接のメンバーであり、ユーザー提供でも削除でもないコンストラクタを選択する
  • C 型の lvalue への xvalue からの代入におけるオーバーロード解決は、 C の直接のメンバーであり、ユーザー提供でも削除でもない代入演算子関数を選択する
  • C はユーザー提供でも削除でもない destructor を持つ

キーワード

final replaceable_if_eligible trivially_relocatable_if_eligible

注記

機能テストマクロ 規格 機能
__cpp_trivial_relocatability 202502L (C++26) 自明な再配置可能性

struct final;      // OK; クラス名'final'を宣言、
                   // クラスプロパティ指定子は使用しない。
struct IF final;   // 不適格: クラスプロパティ指定子は
                   // 関数宣言では使用できない。
struct F final {}; // OK; 指定子はクラスFを派生不可としてマーク。
struct D: F {};    // 不適格: クラスFからは派生できない。
// OK; 指定子は条件を満たす場合にクラスRを𝘳𝘦𝘱𝘭𝘢𝘤𝘦𝘢𝘣𝘭𝘦としてマーク。
struct R replaceable_if_eligible {};
// OK; 指定子は条件を満たす場合にクラスTを𝘵𝘳𝘪𝘷𝘪𝘢𝘭𝘭𝘺 𝘳𝘦𝘭𝘰𝘤𝘢𝘵𝘢𝘣𝘭𝘦としてマーク。
struct T trivially_relocatable_if_eligible {};
// OK; クラスは複数のクラスプロパティ指定子でマーク可能。
struct FRT final replaceable_if_eligible trivially_relocatable_if_eligible {};
// 不適格: 各クラスプロパティ指定子は最大1回のみ使用可能。
struct FRF final replaceable_if_eligible final {};
int main() {}

参考文献

  • C++26標準 (ISO/IEC 14882:2026):
  • 6.8.1 自明に再配置可能かつ置換可能な型 [basic.types.general]

関連項目

final 指定子 (C++11) メソッドがオーバーライドできないこと、またはクラスが派生できないことを宣言する
(C++14)
型がfinalクラス型かどうかをチェックする
(クラステンプレート)