Search code examples
c++c++17ctad

Is there a way to have an alias of a template and preserve Class Template Argument Deduction?


#include <vector>

template<class T>
using vec = std::vector<T>;

int main()
{
    std::vector a{2,3};
    // vec b{2,3}; // not going to work
}

Are we still forced to use macros? There are so many disadvantages in using them...


Solution

  • This is a known problem with CTAD that has been fixed in C++20

    Are we still forced to use macros?

    No. I'd recommend using std::vector if you want CTAD