CTAD is Class Template Argument Deduction in C++17. With CTAD, we can write so-called deduction guides to tell the compiler how to instantiate a class template. Thanks to CTAD, class templates can look more like function templates. There we usually don’t have to state the types other than passing the parameters. The compiler then derives the types from these parameters.
CTAD in std::vector
1 2 3 4
// Before std::vector<int> v{1, 2, 3}; // After std::vector v{1, 2, 3};
CTAD in array
1 2 3 4 5 6 7 8 9 10 11 12
#include<cstddef>
template<typename T, size_t N> structarray { T data[N]; };
template <typename T> structReturnCode { T value; }; // Guide compiler to deduct the type in template argument list template <typename T> ReturnCode(T) -> ReturnCode<T>;