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

履歴 編集

function
<memory>

std::indirect::operator*(C++26)

constexpr const T& operator*() const & noexcept;   // (1)
constexpr T& operator*() & noexcept;               // (2)
constexpr const T&& operator*() const && noexcept; // (3)
constexpr T&& operator*() && noexcept;             // (4)

概要

所有するオブジェクトへの参照を取得する。constなアクセス経路ではconstが所有オブジェクトに伝播する。

事前条件

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

戻り値

  • (1), (2) : 所有するオブジェクトへの参照。
  • (3), (4) : 所有するオブジェクトへの右辺値参照(std::move(*p))。

例外

投げない。

#include <cassert>
#include <memory>
#include <type_traits>

int main()
{
  std::indirect<int> a{42};
  assert(*a == 42);       // 参照の取得
  *a = 10;                // 非const版で書き換え
  assert(*a == 10);

  // constなアクセス経路ではconstが伝播する
  const std::indirect<int> b{5};
  static_assert(std::is_same_v<decltype(*b), const int&>);
}

出力

バージョン

言語

  • C++26

処理系

関連項目

参照