Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-01-05 19:59:41


AlisdairM wrote:
> I am a little confused by the result_of tests, which means either I
> don't understand the library, or there is a problem as most compilers
> are passing!
>
> The basic case:
>
> struct int_result_type { typedef int result_type; };
>
> BOOST_STATIC_ASSERT
> ((
> is_same< result_of< int_result_type(float) >::type, int >::value
> ));
>
>
> If I understand correctly, this is asking what is the result_of a
> function taking a float and returning an int_result_type.

No, this is a common misunderstanding of result_of.

result_of<F(X)> asks "what is the return type of f(x), where f is of type F
and x is of type X?"

So in the above case, it asks what the result would be if we were to create
an instance of int_result_type and call it with 1.0f.

The correct answer is, of course, "a compile time error", but the TR1 spec
forces result_of to report 'int' for the usual reasons. :-)


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