ęœ€ēµ‚ę›“ę–°ę—„ę™‚:
ćŒę›“ę–°

屄歓 編集

function
<functional>

std::reference_wrapper::operator=(C++11)

reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;           //C++11

constexpr reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept; //C++20

ꦂ要

å‚ē…§å…ˆć‚’åˆ‡ć‚Šę›æćˆć‚‹

åŠ¹ęžœ

*thisがx.get()ć‚’ęŒ‡ć™ć‚ˆć†ć«ę›“ę–°ć™ć‚‹

ęˆ»ć‚Šå€¤

*this

例

#include <iostream>
#include <functional>

int main()
{
  int x = 3;
  int y = 5;

  // xćøć®å‚ē…§ć‚’äæęŒć™ć‚‹
  std::reference_wrapper<int> r(x);
  r = std::ref(y); // yćøć®å‚ē…§ć‚’äæęŒć™ć‚‹ć‚ˆć†åˆ‡ć‚Šę›æćˆć‚‹

  r.get() += 1;

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

å‡ŗåŠ›

3
6

ćƒćƒ¼ć‚øćƒ§ćƒ³

čØ€čŖž

  • C++11

処理系