Skip to content

Latest commit

 

History

History
72 lines (52 loc) · 1.66 KB

op_deref.md

File metadata and controls

72 lines (52 loc) · 1.66 KB

operator*

  • memory[meta header]
  • std[meta namespace]
  • indirect[meta class]
  • function[meta id-type]
  • cpp26[meta cpp]
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&>);
}
  • std::indirect[link ../indirect.md]

出力

バージョン

言語

  • C++26

処理系

  • Clang: 22 [mark noimpl]
  • GCC: 16.1 [mark verified]
  • Visual C++: 2026 Update 2 [mark noimpl]

関連項目

参照