std::variant
s#include <x/visitor.H> struct one{}; struct two{}; void foo(const std::variant<one, two> &bar) { std::visit( x::visitor{ [](const one &o) {}, [](const two &t) {} }, bar); }
The x::visitor
template
constructs a callable object for passing to
std::visit
. The intended usage is to pass
a variadic list of lambdas to the template, using uniform initialization
syntax. This constructs a callable object that inherits all passed lambas,
which then gets passed to std::visit
.
typedef std::variant<int, bool> v; template<typename T, typename U=std::enable_if_<x::w::visited<T, v>::value>> struct x{}; x<int> a; // This compiles x<const char *>b; // Compilation error.
x::w::visited<
indicates whether type T
, V
>::valueT
is one of the types
in V
which must be a
std::variant
.
x::w::visited_v<
is an alias for this T
, V
>value
.