From: Daniel Walker (daniel.j.walker_at_[hidden])
Date: 2008-06-24 14:33:04
On Tue, Jun 24, 2008 at 1:19 PM, Giovanni Piero Deretta
> On Tue, Jun 24, 2008 at 7:07 PM, Daniel Walker
> <daniel.j.walker_at_[hidden]> wrote:
>> On Tue, Jun 24, 2008 at 12:51 PM, Daniel Walker
>> <daniel.j.walker_at_[hidden]> wrote:
>>> On Tue, Jun 24, 2008 at 12:12 PM, Mathias Gaunard
>>> <mathias.gaunard_at_[hidden]> wrote:
>>>> Steven Watanabe wrote:
>>>>> Can't you use result_of?
>>>> As far as I can see, the current boost::result_of implementation doesn't
>>>> use decltype or typeof.
>>> The boost::result_of on svn trunk uses decltype when
>>> BOOST_HAS_DECLTYPE is defined. This happens automatically for gcc
>>> versions after 4.2.
>> Correction - for gcc > 4.2, the boost::result_of on svn trunk uses
>> decltype only when you compile with -std=c++0x. It uses the old TR1
>> heuristic otherwise.
> "__decltype()" works even outside of C++0x mode. Shouldn't it be used instead?
C++0x decltype and the TR1 heuristic are not completely compatible
(decltype always succeeds at return type deduction, the heuristic does
not), so I think it's good to only get the new and improved
boost::result_of when using the new and improved standard.
However, there is a need for improving result_of for compilers that
don't explicitly support C++0x decltype, so long as the user knows
when/how it's being improved. Boost.Typeof already aims to provide
aggressive type deduction for an array of compilers with varying
capabilities. As has been suggested, perhaps result_of could use
Boost.Typeof on C++03 compilers, which in turn could use various
compiler extension/hooks when available. So, for example, here's one
way of concisely providing several different strategies for return
type deduction based on the standard and/or compiler's capabilities.
- boost::tr1::result_of uses the legacy heuristic
- boost::cpp0x::result_of uses the standard decltype
- boost::cpp03::result_of uses Boost.Typeof
(see the Boost.Typeof documentation for whether typeof, __decltype,
or the type registry is used)
For C++0x, boost::result_of would be an alias for
boost::cpp0x::result_of. For C++03, boost::result_of would be an alias
for boost::tr1::result_of, so as not to break any existing code. If
users want a better result_of for C++03 compilers, they can explicitly
upgrade from boost::result_of to boost::cpp03::result_of. And of
course, in practice, as compiler vendors supply C++0x standard
libraries, folks will simply use std::result_of. That's probably not
too much to keep track of as we migrate from one standard to the next.
Boost list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk