#pragma once template struct List { struct Container { T* t; Container* next = nullptr; Container(T* t) : t(t) {} }; Container* first = nullptr; Container* last = nullptr; void add(T* t) { Container* c = new Container{t}; first == nullptr ? first = c : last->next = c; last = c; } void forEach(void(*f)(T*)) { for (Container *c = first; c; c = c->next) { f(c->t); } } void empty() { Container *c = first; while (c) { auto n = c->next; delete c; c = n; } } };