Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
std::reference_wrapper
//Title of this code //clang 3.6.0 #include <iostream> #include <vector> #include <functional> int main() { int a = 100; int b = 200; int c = 300; int& cc = c; std::vector<std::reference_wrapper<int>> vec; vec.emplace_back(a); vec.emplace_back(b); vec.emplace_back(cc); std::reference_wrapper<int> x = vec[0]; vec[0] = vec[1]; vec[1] = vec[2]; vec[2] = x; std::cout << a << ", " << b << ", " << c << "\n"; std::cout << vec[0] << ", " << vec[1] << ", " << vec[2] << "\n"; a += 50; b += 50; c += 50; std::cout << vec[0] << ", " << vec[1] << ", " << vec[2] << "\n"; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Optional conversions
Vector examples....
Alternation regex
SubsequenceArray
C++ out of ref
Namespace scope qualifier
Test size_t
pointer to complete array does not convert implicitly to pointer to array of unknown bound
Dynamically allocated array in unique_ptr with custom deleter.
Balanced Insert Example
stackse - search stackoverflow differently
Please log in to post a comment.