views:

608

answers:

3

I hear that tr1::result_of gets used frequently inside of Boost... I'm wondering if there are any good (simple) use cases for tr1::result_of I can use at home.

+3  A: 

A description of result_of is given at open_std.org. Microsoft has a quick example of a unit test wrapper that uses result_of.

Mr Fooz
From the Microsoft example, it seems that the advantage of result_of is that it adds a trait describing the returned type. Thnx!
ceretullis
+3  A: 

There are no simple cases. However, it's used in BOOST_AUTO, which can be used, e.g., in

BOOST_AUTO(x, make_pair(a, b));
Lev
+1  A: 

It's useful when doing meta-programming. The only time I used it was in a wrapper function. If result_of<T>::type was void, the wrapper returned nothing. Otherwise it returns the whatever the wrapped function returns.

Leon Timmermans
just so you know, c++ allows returning void in some cases. for example:"template<class T> T func() { return T(); }" is valid even when T is void.
Evan Teran