Friday, 30 December 2011

decltype on Visual Studio

Visual Studio 2010 had one of the first implementations of C++11's decltype. As such, it has some deficiencies.

One of the deficiencies occurs when you try to get the type of the address of a function template specialisation:

template <typename T>
void f();

decltype(&f<int>) ptr; // error - incorrect argument to 'decltype'

Like every programming problem, this can be worked around with an extra layer of indirection:

template <typename T>
T identity(T);

decltype(identity(&f<int>)) ptr; // ptr has type void(*)()

Hopefully this will be sufficient to get you by.

No comments:

Post a Comment