[#absl-Overload-05] = xref:absl.adoc[absl]::Overload :relfileprefix: ../ :mrdocs: `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>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- 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 [cols="1,4"] |=== | Name| Description | `T...` | |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:absl/Overload-05/2constructor.adoc[`Overload`] [.small]#[constructor]# | For historical reasons we want to support use that looks like a function call: |=== == Using Declarations [cols="1"] |=== | Name | xref:absl/Overload-05/operator().adoc[`operator()`] |=== == Deduction Guides [cols="1,4"] |=== | Name| Description | xref:absl/Overload-0a.adoc[`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. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#