Once again, I wish C++ had stronger typedef
s:
#include <vector>
template<typename T>
struct A {
typedef std::vector<T> List;
};
template<typename T>
void processList(typename A<T>::List list) {
// ...
}
int main() {
A<int>::List list;
processList<int>(list); // This works.
processList(list); // This doesn't.
}
Apparently, the compiler sees list
as a std::vector<int>
and not an A<int>::List
, so it can't match it against the A<T>::List
that is expected.
In the actual case, it's a longer type name, often repeated, and it's a nuisance. Apart from letting processList
accept a vector
instead, is there any way to make template type inference work for me?