typeof(x) as a template argument?

Viewed 1858

I have a variable x, declared as:

auto x = f(y);

where f is a function and y a variable, both defined somewhere else. Now I would like to declare a std::vector holding elements of the type of x, so I write:

std::vector<typeof(x)> v;

This results in a compiler error. A solution is to put here the explicit argument of x, but I think this defeats the purpose of auto in x's declaration! So how can I use the type of x as a template argument, without explicitly writing the type (so that in the type changes, my code remains valid).

1 Answers
Related