Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add polymorphic value like container (#855)
This PR introduces a type `PolymorphicValue<T>` that behaves very similar to `std::unique_ptr<T>`, but preserves knowlegde of how to copy the value. In fact, `PolymorphicValue` only works with copyable types. This allows more convenient handling of interfaces, for types that are copyable and where copying does not have to be avoided. It looks like this: ```cpp struct Base {}; struct Derived {}; std::unique_ptr<Base> up1 = std::make_unique<Derived>(); std::unique_ptr<Base> up2 = up1; // this does not work Acts::PolymorphicValue<Base> pv1 = Acts::makePolymorphicValue<Derived>(); Acts::PolymorphicValue<Base> pv2 = pv1; // this makes a copy of the stored object ``` The reason why I'm adding this is that `pybind11` does not support `std::unique_ptr` as arguments/values on the C++ side, since python lacks a mechanism to release ownership, which would be required in this case. There's a limited number of cases where this is a problem, and where we don't actually care if we copy the stored value.
- Loading branch information