liveBook · Manning

Deduction guide

As explained in Learn C++ by Example

A deduction guide is a declaration that specifies how class template argument deduction interprets constructor arguments.

A deduction guide tells the compiler how constructor arguments determine a class template's parameters. For an Overload built from one lambda, Overload(T) deduces Overload<T>. section 9.3.5

Guiding an Overload

template<typename T> Overload(T) -> Overload<T>; This permits auto overload = Overload{ []() { return 0; } }; and lets overload() invoke the lambda. The same idea extends to a parameter pack of lambdas.

How Learn C++ by Example covers it

How deep it goes
Defines the deduction syntax and applies it to single and variadic lambdas, but does not develop deduction rules broadly.
Examples
Demonstrates Overload<T> construction and a multi-lambda Overload used for hold, nudge, and spin actions.
What it assumes
Assumes lambdas and callable operator() behavior, while connecting those ideas to template parameter deduction.
What you can do after
Apply it via C++ template syntax to construct correctly specialized Overload objects from lambdas.
How it connects
Connects class template argument deduction with lambdas, parameter packs, callable objects, and std::visit.

This explainer was generated by Manning's knowledge graph from the text of Learn C++ by Example. The section links point to the parts of the book it draws on.