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
2008-10-11 06:12:13
From the Microsoft example, it seems that the advantage of result_of is that it adds a trait describing the returned type. Thnx!
ceretullis
2008-10-11 15:51:04
+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
2008-10-11 07:24:54
+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
2008-10-11 12:46:50
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
2008-10-17 18:37:22