Created
January 15, 2018 12:22
-
-
Save Alexey-N-Chernyshov/6d5199ca89e77a09da51720094157d46 to your computer and use it in GitHub Desktop.
Inplace visitor for boost::variant
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
/** | |
* Inplace visitor for boost::variant. | |
* Usage: | |
* boost::variant<int, std::string> value = "1234"; | |
* ... | |
* visit_in_place(value, | |
* [](int v) { std::cout << "(int)" << v; }, | |
* [](std::string v) { std::cout << "(string)" << v;} | |
* ); | |
*/ | |
template <typename TVariant, typename... TVisitors> | |
auto visit_in_place(TVariant &&variant, TVisitors &&... visitors) { | |
return boost::apply_visitor( | |
boost::hana::overload(std::forward<TVisitors>(visitors)...), | |
std::forward<TVariant>(variant)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment