Boost logo

Boost :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2007-05-21 16:20:17


Douglas Gregor wrote:
> On May 21, 2007, at 7:49 AM, Peter Dimov wrote:
>> This special case is needed in situations such as:
>>
>> template<class F> struct X
>> {
>> F f_;
>>
>> result_of<F()>::type operator()() { return f_; }
>>
>> template<class A1>
>> result_of<F(A1)>::type operator()(A1& a1) { return f_(a1); }
>>
>> // ...
>> };
>>
>> where X can be instantiated with non-nullary function objects, or
>> with types
>> that aren't function objects at all, as in:
>>
>> X<int> x;
>>
>> The above instantiates the declaration of X::operator()(), which
>> attempts to
>> instantiate result_of<int()>, which would fail without the kludge.
>
> Yep, this is exactly the reason.
>
>> With variadic templates a special case is no longer necessary and I
>> believe
>> that the C++0x result_of no longer has one.
>
> As soon as decltype gets in the language, result_of just "does the
> right thing" without this (or any) kludges. The LWG has accepted the
> appropriate change in principle, but of course it can't go in until
> decltype goes in.
>

Well, that last paragraph reads confusing to me.

What is decltype(an_int()) or decltype(non_callable()), then? No compile
error?!

And isn't result_of working around a problem elsewhere in the language
(namely the non-lazy instantiation of the nullary call operator), in
fact making the switch to a decltype-based implementation harder?

Regards,
Tobias


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