Search⌘ K

Deduction Guides

Explore deduction guides in C++17 to understand how the compiler deduces template class types automatically or through user-defined guides. Learn examples including std::array and custom guides for improved template usage. Understand the limitations of deduction guides in C++17 and their planned improvements.

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:

  1. compiler-generated (implicitly generated)
  2. 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...) ->