example1_basic_usage.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <functional>
#include <iostream>

int main() {
    int x = 10;
    std::reference_wrapper<int> ref = x;
    int x1 = 10;
    const int& y1 = x1;
    y1 = 30;
    std::cout << "updated x1: " << x1 << std::endl;
    
    std::cout << "Value: " << ref << std::endl;
    
    ref.get() = 20;
    std::cout << "Updated value: " << x << std::endl;
    
    return 0;
}
Back to std_reference_wrapper