Skip to content

Files

61 lines (42 loc) · 853 Bytes

op_cast_ref_t.md

File metadata and controls

61 lines (42 loc) · 853 Bytes

operator T&

  • functional[meta header]
  • std[meta namespace]
  • reference_wrapper[meta class]
  • function[meta id-type]
  • cpp11[meta cpp]
operator T& () const noexcept;            //C++11

constexpr operator T& () const noexcept;  //C++20

概要

生参照への変換

戻り値

保持している参照を返す

例外

投げない

#include <iostream>
#include <functional>

int main()
{
  int x = 3;

  std::reference_wrapper<int> r(x);
  int& rx = r; // 参照に暗黙変換する
  rx += 1;

  std::cout << x << std::endl;
}

出力

4

バージョン

言語

  • C++11

処理系

参照