C++26's std::polymorphic lets you copy polymorphic objects without writing clone()

Composite objects and C++26 the std:polymorphic type

Marius Bancila shows how std::polymorphic, new in C++26, restores value semantics to classes that own polymorphic components. Using an event-log example, he contrasts the old unique_ptr plus virtual clone() approach—which breaks copyability, leaks infrastructure into the interface, and fails to propagate const—with std::polymorphic, which deep-copies correctly via type erasure captured at construction, enforces deep const, and can never be null. The result: the Rule of Zero applies again.

The only empty state is moved-from, explicitly detectable via valueless_after_move(), so every dereference elsewhere is valid by invariant.

More from this day

2026-10-21