Applies a set of callables to a std::variant using std::visit and Overload.
<mrdocs/ADT/Overload.hpp>
template<
class Variant,
class... Ts>
constexpr
decltype(auto)
match(
Variant&& v,
Ts...&&... xs);
This is a convenience wrapper around std::visit(makeOverload(...), variant). It forwards the variant and the callables and returns whatever std::visit returns.
std::variant<int, std::string> v = 42;
auto r = fn::match(v,
[](int i) { return i + 1; },
[](const std::string& s) { return s.size(); }
);
Name | Description |
---|---|
v | The variant to visit (can be lvalue or rvalue; const-qualification is preserved). |
xs | The callables to be combined with makeOverload and passed to std::visit. |