Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Class template argument deduction

Use case

Cleaner standard library usage.

Explanation

CTAD lets us omit template arguments when the compiler can deduce them from constructor arguments.

Code

#include <iostream>
#include <vector>

int main() {
  std::vector addresses{0x1000, 0x1100, 0x1200};

  std::cout << "Vector size: " << addresses.size() << " \n";

  return 0;
}

View on GitHub.

Output

$ ./src/c++17/build/class-template-argument-deduction
Vector size: 3