Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
template<typename TBase, typename... Types>
constexpr auto polymorphic_get(std::variant<Types...>& v)
-> std::enable_if_t<(std::is_base_of_v<TBase, Types> && ...), TBase&>
{
return *std::visit([](auto& x){ return dynamic_cast<TBase*>(&x); }, v);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment