Last active
October 7, 2016 18:15
-
-
Save bryancatanzaro/95a885ffe021502d5456dbeb16fe594d 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 T> | |
struct get_optional_visit { | |
template<typename U> | |
std::optional<T> operator()(U) const { | |
return std::optional<T>(); | |
} | |
std::optional<T> operator()(const T& t) const { | |
return std::optional<T>(t); | |
} | |
}; | |
template<typename T, typename Variant> | |
std::optional<T> get_optional(Variant v) { | |
return std::visit(get_optional_visit<T>(), v); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment