Returns an opaquely‐typed Callable object whose operator() overload set is the sum of the operator() overload sets of each CallableT in CallableTs.

Synopsis

Declared in <llvm/ADT/STLExtras.h>

template<typename... CallableTs>
constexpr
decltype(auto)
makeVisitor(CallableTs&&... Callables);

Description

The type of the returned object derives from each CallableT in CallableTs. The returned object is constructed by invoking the appropriate copy or move constructor of each CallableT, as selected by overload resolution on the corresponding argument to makeVisitor.

Example:

auto visitor = makeVisitor([](auto) { return "unhandled type"; },
                           [](int i) { return "int"; },
                           [](std::string s) { return "str"; });
auto a = visitor(42);    // `a` is now "int".
auto b = visitor("foo"); // `b` is now "str".
auto c = visitor(3.14f); // `c` is now "unhandled type".

Example of making a visitor with a lambda which captures a move‐only type:

std::unique_ptr<FooHandler> FH = /* ... */;
auto visitor = makeVisitor(
    [FH{std::move(FH)}](Foo F) { return FH->handle(F); },
    [](int i) { return i; },
    [](std::string s) { return atoi(s); });

Return Value

A visitor whose call operators are the sum of Callables.

Parameters

Name

Description

Callables

Callables whose call operators are combined.

Created with MrDocs