Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
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.
move_string
Forgetting to check end
Crow unordered_map Quiz
SimpleList Example
bubble sort
Unlike C (even C99/C11), C++ allows initializers in if-conditions, so this compiles.
12/2
Balanced Insert Example
Dash-D compiler flag example
illegal instruction (SIGILL)
Please log in to post a comment.