Skip to content

Latest commit

 

History

History
71 lines (51 loc) · 1.76 KB

op_constructor.md

File metadata and controls

71 lines (51 loc) · 1.76 KB

コンストラクタ

  • iterator[meta header]
  • std[meta namespace]
  • move_sentinel[meta class]
  • function[meta id-type]
  • cpp20[meta cpp]
constexpr move_sentinel();                              // (1)

constexpr explicit move_sentinel(S s);                  // (2)

template<class S2>
  requires convertible_to<const S2&, S>
constexpr move_sentinel(const move_sentinel<S2>& s);    // (3)
  • convertible_to[link /reference/concepts/convertible_to.md]

概要

move_sentinelオブジェクトを構築する。

効果

Sの番兵オブジェクトをlastというメンバ変数に保持しているとする。

  • (1) : lastを値初期化する(last{}相当の初期化)。
  • (2) : laststd::move(s)によって初期化する。
  • (3) : lasts.lastによって初期化する。

定数式に評価される条件

#include <iterator>
#include <vector>

int main() {
  std::vector<int> vec = {1, 2, 3};
  auto se = std::end(vec);

  // (1) デフォルト構築
  std::move_sentinel<std::vector<int>::iterator> ms1{};

  // (2) 番兵を渡して構築
  std::move_sentinel ms2{se};

  // (3) コピー構築
  std::move_sentinel<std::vector<int>::iterator> ms3{ms2};
}
  • std::move_sentinel[color ff0000]

出力

バージョン

言語

  • C++20

処理系

参照