C++26 adds std::polymorphic for value-semantic polymorphic composition
A follow-up article on C++26's std::indirect feature introduces std::polymorphic, a new standard library type aimed at building composite classes that own polymorphic member objects while remaining copyable, regular values. The piece illustrates the problem using a smart-house EventLog example, showing how existing approaches like storing a base class directly, using unique_ptr, or using std::variant each fail to cleanly support an open set of event types with proper value semantics.
GoKawiil's interpretation of the reporting above, not reported fact.
This addition could simplify common C++ design patterns—such as strategy objects, AST nodes, and shape hierarchies—where developers previously had to choose between manual copy logic, pointer indirection, or closed-set variants. By offering a standard-library solution, std::polymorphic may reduce boilerplate and bugs tied to slicing, null pointers, or const-propagation issues in polymorphic composition.
- std::polymorphic is a new C++26 standard library type for composite classes with owned polymorphic members.
- It aims to preserve value semantics (copyability, regularity) while supporting an open set of derived types.
- Existing alternatives like base-class members, unique_ptr, and std::variant each have drawbacks the new type seeks to address.
C++ Programming Language reference book — If you're diving into modern C++26 features like std::polymorphic and std::indirect, having a solid reference on core language design and idioms is invaluable. This classic text helps ground advanced value-semantics patterns like composite ownership and PImpl in fundamental C++ principles. A great companion for developers exploring these new standard library types.
See C++ Programming Language reference book on Amazon → Affiliate link — we may earn a commission on purchases, at no extra cost to you. Product picked by AI based on this article; it is not a tested recommendation.Source: mariusbancila.ro — Marius Bancila, 2026-10-19
Published there as: “Composite objects and C++26 the std:polymorphic type”
Read the original report → The summary and analysis above are GoKawiil's own, written from reporting by the source above. Facts and quotes belong to the original publisher.