Function Subspace :: sus :: boxed :: dyn

template <class DynC, class ConcreteT>
auto dyn(ConcreteT& t) -> Dyn<DynC, ConcreteT>
requires
std::same_as<DynC, std::remove_cvref_t<DynC>>
std::same_as<ConcreteT, std::remove_cvref_t<ConcreteT>>
template <class DynC, class ConcreteT>
auto dyn(ConcreteT&& t) -> Dyn<DynC, ConcreteT>
requires
std::same_as<DynC, std::remove_cvref_t<DynC>>
std::same_as<ConcreteT, std::remove_cvref_t<ConcreteT>>
std::is_rvalue_reference_v<ConcreteT &&>
template <class DynC, class ConcreteT>
auto dyn(const ConcreteT& t) -> Dyn<DynC, ConcreteT>
requires
std::same_as<const DynC, const std::remove_cvref_t<DynC>>
std::same_as<ConcreteT, std::remove_cvref_t<ConcreteT>>
std::is_const_v<DynC>

Type erases a reference to a type T& which satisfies a concept C, into a reference DynC& that also satisfies C but without templates.

Use dyn<DynC>(x) to convert a mutable reference to x into DynC& and dyn<const DynC>(x) to convert a const or mutable reference to x into const Dyn&.

Type erasure into DynC allows calling a method that receives a DynC reference, such as const DynC&, without requiring a heap allocation into a Box<DynC>.

See DynConcept for more on type erasure of concept-satisfying types.