Request Short Link
C++ 98
C++ 11
C++ 14
C++ 17
C++ 20
C++ 23
C++ 2c
for-loops as while-loops
array subscription
Show all implicit casts
Show all template parameters of a CallExpr
Use libc++
Transform std::initializer_list
Show noexcept internals
Show padding information
Show coroutine transformation
Show C++ to C transformation
Show object lifetime
Default
15
18
20
22
26
More
GitHub
Patreon
Issues
About
Policies
Examples
C++ Insights @ YouTube
Settings
Version
None
×
Made by
Andreas Fertig
Powered by
Flask
and
CodeMirror
Source:
#include <iostream> #include <memory> using namespace std; struct X { X() { p = new int; } ~X() { delete p; } int *p; // move constructor X(X &&rhs) { cout << "X::move_cc" << endl; p = rhs.p; rhs.p = nullptr; } // move assignment X &operator=(X &&rhs) { cout << "X::move_ao" << endl; if (this == &rhs) { return *this; } delete p; p = rhs.p; rhs.p = nullptr; return *this; } }; template <typename T> void my_swap(T &x, T &y) { T t = move(x); x = move(y); y = move(t); }; int main() { // ranged based for const int arr[10]{2,4,6,8}; for (const auto &x : arr) { cout << x << endl; } // lambda function auto f = [](int a, int b) { return a+b; }; cout << f(10, 20) << endl; // smart pointer auto p = make_unique<int>(); *p = 5; // swapping X a, b; cout << a.p << " " << b.p << endl; my_swap(a, b); cout << a.p << " " << b.p << endl; // uses move-cc and move-ao return 0; }
Insight:
Console: