absl::Overload is a functor that provides overloads based on the functors with which it is created. This can, for example, be used to locally define an anonymous visitor type for std::visit inside a function using lambdas.

Synopsis

Declared in <absl/functional/overload.h>

template<typename... T>
struct Overload final
    : T...

Description

Before using this function, consider whether named function overloads would be a better design.

Example:

std::variant<std::string, int32_t, int64_t> v(int32_t{1}); const size_t result = std::visit(absl::Overload{ []std::string& s) { return s.size(); }, []auto& s) { return sizeof(s); }, }, v); assert(result == 4);

Base Classes

Name

Description

T...

Member Functions

Name

Description

Overload [constructor]

For historical reasons we want to support use that looks like a function call:

Using Declarations

Name

operator()

Deduction Guides

Name

Description

Overload<T...>

Before C++20, which added support for CTAD for aggregate types, we must also teach the compiler how to deduce the template arguments for Overload.

Created with MrDocs