Matching types

Easily match values by type.

Name Description
match Match by type.
match_else Match anything.
Class Description
piped::adl_match Behavior for matching M on a type T for match<M>

<T> match

<piped/match.hpp>

template<typename T>
constexpr detail::match_<T> piped::match

Description

Match by type.

Example:

template<typename T>
void F(T v) {
    v
    | match<int>   <= [](auto i) { say("F int"); }
    | match<float> <= [](auto f) { say("F float"); }
    | match_else   <= [](auto v) { say("None of the above!"); }
    ;
}

This provides a pipe-based visitor syntax for matching values on type. The function provided to the first encountered match will be called; further matches will be skipped. match_else can be used to match any other case.

One can customize how type matching is done by specializing adl_match.

operator<= is abused overloaded to provide slightly nicer syntax. One can also call using match<T>([](...){ }).

match_else

match_else

<piped/match.hpp>

constexpr detail::match_else_ piped::match_else

Description

Match anything.

match