[Typeof] Why not use decltype?

The Boost.Typeof library does a lot of work to determine the type of an expression. At last week's meeting, the C++ committee voted to add "decltype" into the C++0x standard. decltype is what we want from typeof: a proper, reference-preserving way to get the type of an arbitrary expression. As of today, GCC 4.3's experimental C++0x mode contains support for decltype. I have updated the Boost Config library (on the CVS trunk) to contain BOOST_HAS_DECLTYPE, indicating the presence of decltype. A sufficiently-motivated person could certainly use this macro to give a simple implementation of decltype for C++0x compilers... There is nightly testing of Boost's trunk on the latest version of GCC 4.3 (also built nightly), so we will get appropriate testing of C+ +0x features throughout Boost. - Doug

"Doug Gregor" <dgregor@osl.iu.edu> wrote
I have updated the Boost Config library (on the CVS trunk) to contain BOOST_HAS_DECLTYPE, indicating the presence of decltype. A sufficiently-motivated person could certainly use this macro to give a simple implementation of decltype for C++0x compilers...
Could you ellaborate? It's not quite clear how to implement decltype on compilers that don't have it... which means on any compiler other than the latest gcc that you mentioned... or am I missing something? Regards, Arkadiy

On Jul 27, 2007, at 3:10 PM, Arkadiy Vertleyb wrote:
"Doug Gregor" <dgregor@osl.iu.edu> wrote
I have updated the Boost Config library (on the CVS trunk) to contain BOOST_HAS_DECLTYPE, indicating the presence of decltype. A sufficiently-motivated person could certainly use this macro to give a simple implementation of decltype for C++0x compilers...
Could you ellaborate? It's not quite clear how to implement decltype on compilers that don't have it... which means on any compiler other than the latest gcc that you mentioned... or am I missing something?
I meant, why not have the typeof library use decltype when it is available? You can just predicate on BOOST_HAS_DECLTYPE, and of course test with the latest GCC 4.3. - Doug

"Doug Gregor" <dgregor@osl.iu.edu> wrote
I meant, why not have the typeof library use decltype when it is available? You can just predicate on BOOST_HAS_DECLTYPE, and of course test with the latest GCC 4.3.
I think BOOST_TYPEOF should continue returning consistent result across the compilers. For this, if we used decltype, we would need to remove top-level consts and refs... which doesn't seem to make a lot of sense... Does GCC 4.3 still have typeof? If a person needs the decltype functionality, he could use it on newer compilers, but would need to specifically address portability issues (if needed) in a non-trivial way, since it doesn't look possible to correctly emulate decltype :-( Regards, Arkadiy

On Jul 27, 2007, at 4:16 PM, Arkadiy Vertleyb wrote:
"Doug Gregor" <dgregor@osl.iu.edu> wrote
I meant, why not have the typeof library use decltype when it is available? You can just predicate on BOOST_HAS_DECLTYPE, and of course test with the latest GCC 4.3.
I think BOOST_TYPEOF should continue returning consistent result across the compilers. For this, if we used decltype, we would need to remove top-level consts and refs... which doesn't seem to make a lot of sense...
typename remove_cv<typename remove_reference<decltype(EXPR)
::type>::type
is still a lot simpler than what BOOST_TYPEOF has to go through to get the type of an expression... you could save a lot of compile time using decltype.
Does GCC 4.3 still have typeof?
It's still there, although I don't know how useful it is. - Doug

"Doug Gregor" <dgregor@osl.iu.edu> wrote
"Doug Gregor" <dgregor@osl.iu.edu> wrote
I meant, why not have the typeof library use decltype when it is available? You can just predicate on BOOST_HAS_DECLTYPE, and of course test with the latest GCC 4.3.
I think BOOST_TYPEOF should continue returning consistent result across the compilers. For this, if we used decltype, we would need to remove top-level consts and refs... which doesn't seem to make a lot of sense...
typename remove_cv<typename remove_reference<decltype(EXPR)
::type>::type
is still a lot simpler than what BOOST_TYPEOF has to go through to get the type of an expression... you could save a lot of compile time using decltype.
Well, if typeof is available, BOOST_TYPEOF does use it rather than perform the emulation, so it's rather something like: #define BOOST_TYPEOF(expr) typeof(expr) (or almost like this)
Does GCC 4.3 still have typeof?
It's still there, although I don't know how useful it is.
Doesn't GCC care about backward compatibility? Regards, Arkadiy

On Jul 27, 2007, at 4:38 PM, Arkadiy Vertleyb wrote:
Does GCC 4.3 still have typeof?
It's still there, although I don't know how useful it is.
Doesn't GCC care about backward compatibility?
Yes, but they worry a lot less about backward compatibility for GCC extensions, especially when those extensions are superseded by real language features. That said, I don't believe that anyone has proposed removing "typeof" from GCC. - Doug

"Doug Gregor" <dgregor@osl.iu.edu> wrote
On Jul 27, 2007, at 4:38 PM, Arkadiy Vertleyb wrote:
Does GCC 4.3 still have typeof?
It's still there, although I don't know how useful it is.
Doesn't GCC care about backward compatibility?
Yes, but they worry a lot less about backward compatibility for GCC extensions, especially when those extensions are superseded by real language features. That said, I don't believe that anyone has proposed removing "typeof" from GCC.
Maybe it does make sence to use decltype where available rather than typeof, since decltype is supposed to be better supported... Having said this, the decltype functionality that makes it decltype can not be available through BOOST_TYPEOF due to portability issues :-( Regards, Arkadiy
participants (2)
-
Arkadiy Vertleyb
-
Doug Gregor