Share via


Will MSVC support a __typeof__ operator (like in GCC)?

Question

Friday, June 4, 2010 1:11 AM

Hi,

While meta-programming, I would love to get the type of a variable as a compiler-recognized type, without having to explicitly name the type in code. For example:

typedef __typeof__(x) MyType; // x is a variable, not a type, but MyType is a type.

I used __typeof__ in my above example, because it is supported by GCC. The following web page talks more about it:

http://www.cims.nyu.edu/cgi-comment/info2html?(gcc)Typeof

 

I would be very happy if MSVC supported something like this. Can we expect something similar soon?

 

Thanks,

Manu.

All replies (3)

Friday, June 4, 2010 1:35 AM âś…Answered | 1 vote

1. VC++ 2010 has decltype.

2. boost.typeof has worked natively in VC++ since at least VC++ 2003, allowing for very similar semantics to decltype.


Friday, June 4, 2010 4:55 PM

Thanks! It's good to find out that VC++ 2010 supports decltype. I'm working in VC++ 2008, and it looks like boost implements BOOST_TYPEOF using a hack/workaround specific to the 2008 compiler. It'll be nice to not depend on that once I move to VC++ 2010.


Friday, June 4, 2010 5:03 PM

BOOST_TYPEOF's VC++ implementation is the same for VC++ 2003 - VC++ 2010. (BOOST_TYPEOF doesn't use decltype for VC++ yet, even 2010, as they have slightly different semantics in regards to references).