Boost logo

Boost :

Subject: Re: [boost] [result_of] now uses decltype on release branch
From: Eric Niebler (eric_at_[hidden])
Date: 2012-09-10 22:14:38


On 9/10/2012 5:05 AM, Michel Morin wrote:
> Eric Niebler wrote:
>>> template < class , class = void >
>>> struct result_of_aux
>>> {};
>>>
>>> template < class F, class ...Args>
>>> struct result_of_aux<F(Args...),
>>> decltype(std::declval<F>()(std::declval<Args>()...), void ())>
>>> {
>>> typedef decltype(std::declval<F>()(std::declval<Args>()...)) type;
>>> };
>>
>> What is void()? That's not any expression I recognize. It's a function
>> type.
>
> 5.2.3 [expr.type.conv] p2
> The expression T(), where T is a simple-type-specifier or typename-specifier
> for a non-array complete object type or the (possibly cv -qualified)
> void type,
> creates a prvalue of the specified type, which is value-initialized ( 8.5; no
> initialization is done for the void() case).

A prvalue of type void? That's whack.

>> Anyway, keep in mind that std::declval<F>()(...) could have an
>> incomplete type, so you can't really use it in an expression.
>> You should use it in decltype,
>
> All the use of `std::declval<F>()(...)` is in decltype
> and so I don't see any problem in the code.
> Do you mean
> struct result_of_aux<
> F(Args...)
> , decltype(std::declval<F>()(std::declval<Args>()...), void ())
> >
> can be a hard error?

Yes indeedy.

    struct X;
    X foo();

    typedef decltype(foo()) Y; // OK
    typedef decltype(foo(), void()) Z; // ERROR

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk