Skip to content

Latest commit

 

History

History
86 lines (65 loc) · 2.3 KB

File metadata and controls

86 lines (65 loc) · 2.3 KB

move_constructible

  • concepts[meta header]
  • concept[meta id-type]
  • std[meta namespace]
  • cpp20[meta cpp]
namespace std {
  template<class T>
  concept move_constructible = constructible_from<T, T> && convertible_to<T, T>;
}

概要

move_constructibleは、任意の型Tがムーブ構築可能であること表すコンセプトである。

モデル

Tがオブジェクト型ならばrvをTの右辺値、u2をrvと等値なTのオブジェクトとすると、このrv, u2について以下の条件を満たす場合に限って型Tはmove_constructibleのモデルである。

  • T u = rv;の定義の後ではuとu2は等値であること
  • T(rv)はu2と等値であること
  • Tがconstではないのであれば、上記の2つの条件内の式の後のrvは有効だが未規定な状態となる。そうでなければrvは変更されない。
    • 標準ライブラリの型のオブジェクトはムーブされた後では有効だが未規定な状態となる。

例

#include <iostream>
#include <concepts>

template<std::move_constructible T>
void f(const char* name) {
  std::cout << name << " is move constructible" << std::endl;
}

template<typename T>
void f(const char* name) {
  std::cout << name << " is not move constructible" << std::endl;
}

struct S {
  S(S&&) = delete;
  
  S(int m) : n(m) {}

  int n = 0;
};

struct M {
  M(M&&) = default;
};

int main() {
  f<int>("int");
  f<S>("S");
  f<M>("M");
}
  • std::move_constructible[color ff0000]

出力

int is move constructible
S is not move constructible
M is move constructible

バージョン

言語

  • C++20

処理系

  • Clang: 13.0.1 [mark verified]
  • GCC: 10.1 [mark verified]
  • Visual C++: 2019 Update 3 [mark verified]

関連項目

参照