最終更新日時(UTC):
が更新

履歴 編集

function
<memory>

std::indirect::operator->(C++26)

constexpr const_pointer operator->() const noexcept; // (1)
constexpr pointer operator->() noexcept;             // (2)

概要

所有するオブジェクトのメンバへアクセスするためのポインタを取得する。

事前条件

*thisが無効値状態でないこと。

戻り値

所有するオブジェクトを指すポインタ。

例外

投げない。

#include <cassert>
#include <memory>
#include <string>

int main()
{
  std::indirect<std::string> s{std::string{"hello"}};
  assert(s->size() == 5);  // 所有するstringのメンバにアクセス
  s->push_back('!');
  assert(*s == "hello!");
}

出力

バージョン

言語

  • C++26

処理系

関連項目

参照