How to typedef a template class? [duplicate]

Yes. It is called an “alias template,” and it’s a new feature in C++11.

template<typename T>
using MyVector = std::vector<T, MyCustomAllocator<T>>;

Usage would then be exactly as you expect:

MyVector<int> x; // same as: std::vector<int, MyCustomAllocator<int>>

GCC has supported it since 4.7, Clang has it since 3.0, and MSVC has it in 2013 SP4.

Leave a Comment