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
New C++ Insights Episode
×
Made by
Andreas Fertig
Powered by
Flask
and
CodeMirror
Source:
template<typename T> struct Node { T data; Node * next = nullptr; Node(const T &data = T()) : data(data) {} }; template<typename T> class MyLList { Node<T> * head = new Node<T>, *tail = head; public: class MyIterator; using iterator = MyIterator; iterator begin() { return iterator(head->next); } iterator end() { return iterator(nullptr); } void insert_after(const T& value) { tail->next = new Node(value); tail = tail->next; } }; template<typename T> class MyLList<T>::MyIterator { Node<T> * val; public: MyIterator(Node<T> * val) : val(val) {} MyIterator& operator++() { val = val->next; return *this; } bool operator!=(const MyIterator &it) { return val != it.val; } T& operator*() { return val->data; } }; #include <algorithm> #include <iostream> int main() { MyLList<int> list; list.insert_after(3); list.insert_after(4); list.insert_after(6); list.insert_after(5); using std::cout; for (auto i : list) cout << i << ' '; cout << '\n'; std::for_each(list.begin(), list.end(), [](int &x) { x *= 2; }); for (auto i : list) cout << i << ' '; return 0; }
Insight:
Console: