Article

C++26: std::polymorphic

Sandor Dargo ·Sandor Dargo's Blog ·Published 2026-08-19 ·5 min read

This article discusses the new std::polymorphic feature in C++26, detailing its implications and usage. It provides insights into how this feature enhances polymorphism in C++.

From the article

In the previous article , we looked at std::indirect — C++26’s answer to the “I need a heap-allocated member with value semantics” problem. indirect<T> always stores exactly a T . But what if you need to store a Circle or a Rectangle through a Shape base class — and copy it without slicing?

That’s std::polymorphic<T> , the other half of P3019R14 . It owns a heap-allocated object whose dynamic type may be T or any type derived from T . Copying performs a type-erased deep copy that preserves the dynamic type. No virtual clone() needed.

To have a copyable collection of polymorphic objects, every derived class needs a virtual clone() method. Let’s see what that looks like:


Share this resource


Discovered 2026-08-20 Source Sandor Dargo's Blog Archive 2026-08 →