Created
September 16, 2018 10:16
-
-
Save isc30/5c90e11b2bdeac3c82d6bfdce72167d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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