2011-06-17 CPlusPlus0X

More on type inference

Together with auto there is a new keyword decltype. It is used to determine the type of an expression in compile time. You can do like this:

auto var1 = 3.14;
decltype(var1) var2;

var2 will get the same type as var1. Who in it its turn got its type from the initialization with 3.14 and so they are both doubles.

Right now it might not be entirely obvious what this is good for, and it is probably of most use for library developers, but now you have seen it anyway.