Created
December 13, 2020 23:53
-
-
Save BigRedEye/d2c70d3b2d95af5e152729fad9b3fbd6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #pragma once | |
| #include <utility> | |
| #include <variant> | |
| template <typename... Ts> | |
| struct Overloaded : Ts... { | |
| using Ts::operator()...; | |
| }; | |
| template <typename... Ts> | |
| Overloaded(Ts...) -> Overloaded<Ts...>; | |
| template <typename T> | |
| class Matcher { | |
| public: | |
| template <typename U> | |
| Matcher(U&& value) : value_{std::forward<U>(value)} { | |
| } | |
| template <typename F> | |
| decltype(auto) operator<<=(F&& f) { | |
| return std::visit(std::forward<F>(f), std::forward<T>(value_)); | |
| } | |
| private: | |
| T&& value_; | |
| }; | |
| template <typename U> | |
| Matcher(U &&) -> Matcher<U&&>; | |
| #define match(var) Matcher(var) <<= Overloaded |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment