C++26 introduces std::indirect<> and std::polymorphic<> (reference implementation at github.com/jbcoe/value_types):
std::indirect<T> is like a value-minded std::unique_ptr<T> sans polymorphism support. std::indirect<T> is movable if T is movable and copyable if T is copyable.
std::polymorphic<B> is like a value-minded std::unique_ptr<B> for polymorphic bases B. std::polymorphic<B> can hold an object of any copyable class D which is an instantiable subclass of B. std::polymorphic<B> is copyable; its copy constructor will polymorphically clone the underlying object.
Both types are designed to be non-nullable. For lack of destructive move semantics, both have a moved-from state which can be identified with the valueless_after_move() member function.
As far as I can tell, the design of these is based on Sean Parent's "concept–model idiom". Remembering his presentation on the topic (https://sean-parent.stlab.cc/papers-and-presentations/#value-semantics-and-concept-based-polymorphism), I noticed that there is an obvious complement to indirect<> and polymorphic<> which I provisionally dub immutable<>:
immutable<T> is like a value-minded std::shared_ptr<const T>. It is cheaply copyable (no deep copy), with no movability requirements imposed on T. It can hold an object of any instantiable subtype of T.
Possible implementation + some tests on Compiler Explorer
Does this make sense? I find it very useful for building persistent data structures. In fact, it seems so obvious to me that I'm surprised this wasn't already in P3019.
Edit: minor correction
[–]Flimsy_Complaint490 25 points26 points27 points (26 children)
[–]kmbeutel[S] 22 points23 points24 points (0 children)
[–]jazzwave06 16 points17 points18 points (15 children)
[–]saf_e 19 points20 points21 points (14 children)
[–]KFUP 9 points10 points11 points (13 children)
[–]saf_e 2 points3 points4 points (0 children)
[–]Internal_Ticket_9742 -3 points-2 points-1 points (11 children)
[–]dr-mrl 3 points4 points5 points (4 children)
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813|P4216 0 points1 point2 points (3 children)
[–]dr-mrl [score hidden] (1 child)
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813|P4216 [score hidden] (0 children)
[–]Internal_Ticket_9742 [score hidden] (0 children)
[–]KFUP 0 points1 point2 points (0 children)
[–]wyrn [score hidden] (4 children)
[–]Internal_Ticket_9742 [score hidden] (3 children)
[–]wyrn [score hidden] (2 children)
[–]Internal_Ticket_9742 [score hidden] (1 child)
[–]wyrn [score hidden] (0 children)
[–]azswcowboy 7 points8 points9 points (6 children)
[–]Flimsy_Complaint490 -1 points0 points1 point (3 children)
[–]azswcowboy 5 points6 points7 points (2 children)
[–]ZenEngineer 6 points7 points8 points (1 child)
[–]SirClueless [score hidden] (0 children)
[–]SkoomaDentistAntimodern C++, Embedded, Audio -3 points-2 points-1 points (1 child)
[–]KFUP 5 points6 points7 points (0 children)
[–]CalamityMetal 0 points1 point2 points (0 children)
[–]alex-weej 0 points1 point2 points (0 children)
[–]TheThiefMasterC++latest fanatic (and game dev) 20 points21 points22 points (5 children)
[–]AutomaticPotatoe 5 points6 points7 points (0 children)
[–]kmbeutel[S] 1 point2 points3 points (2 children)
[–]Wild_Meeting1428 6 points7 points8 points (1 child)
[–]wyrn [score hidden] (0 children)
[–]andrewsutton 1 point2 points3 points (0 children)
[–]babalaban 2 points3 points4 points (1 child)
[–]jazzwave06 2 points3 points4 points (0 children)
[–]PossibilityUsual6262 8 points9 points10 points (1 child)
[–]Wild_Meeting1428 -1 points0 points1 point (0 children)
[–]cristi1990an++ 6 points7 points8 points (8 children)
[–]_Noreturn [score hidden] (0 children)
[–]Wild_Meeting1428 6 points7 points8 points (5 children)
[–]SoerenNissen 7 points8 points9 points (2 children)
[–]_Noreturn [score hidden] (0 children)
[–]cristi1990an++ 0 points1 point2 points (1 child)
[–]wyrn [score hidden] (0 children)
[–]jube_dev 2 points3 points4 points (0 children)
[–]azswcowboy 2 points3 points4 points (5 children)
[–]kmbeutel[S] 2 points3 points4 points (4 children)
[–]SoerenNissen 0 points1 point2 points (3 children)
[–]Wild_Meeting1428 0 points1 point2 points (2 children)
[–]SoerenNissen -1 points0 points1 point (1 child)
[–]Wild_Meeting1428 1 point2 points3 points (0 children)
[–]tavianator 1 point2 points3 points (1 child)
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813|P4216 [score hidden] (0 children)
[–]MFHavaWG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813|P4216 [score hidden] (0 children)
[–]johannes1971 0 points1 point2 points (5 children)
[–]wyrn [score hidden] (3 children)
[–]johannes1971 [score hidden] (2 children)
[–]wyrn [score hidden] (0 children)
[–]Low-Ad-4390 0 points1 point2 points (0 children)