Skip to content

Instantly share code, notes, and snippets.

@isc30
Created September 16, 2018 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isc30/5c90e11b2bdeac3c82d6bfdce72167d6 to your computer and use it in GitHub Desktop.
Save isc30/5c90e11b2bdeac3c82d6bfdce72167d6 to your computer and use it in GitHub Desktop.
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