Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-05-21 07:49:54


Eric Niebler wrote:

> I've noticed something odd about the specification of tr1::result_of.
> In result_of<F()>::type, if F is a class type that doesn't have a
> nested result_type typedef, the result is "void". This is only true
> for F(); that is, when there are no arguments.

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.

There's no such problem with the A1 overload since, as a template, it's not
instantiated unless used.

With variadic templates a special case is no longer necessary and I believe
that the C++0x result_of no longer has one.


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