Deduction Guides
The lesson focuses on how compiler uses special rules called “Deduction Guides” to work out the template class types.
We'll cover the following
Deduction Guides
The compiler uses special rules called “Deduction Guides” to work out the template class types. We have two types of guides:
- compiler-generated (implicitly generated)
- user-defined
To understand how the compiler uses the guides, let’s look at an example.
Here’s a custom deduction guide[^arrded] for std::array
:
[^arrded]: simplified version of libstdc++
template<typename T, typename... U>
array(T, U...) ->
array<enable_if_t<(is_same_v<T, U> && ...), T>, 1 + sizeof...(U)>;
Get hands-on with 1400+ tech skills courses.