
On Apr 21, 2013, at 9:35 PM, "Peter Dimov"
Jeffrey Lee Hellrung, Jr. wrote:
On Sun, Apr 21, 2013 at 7:48 AM, Daniel Walker
wrote: This is due to a dark corner of TR1: the result and result_type members are consulted in non-nullary functors but nullary functors always > generate void. (See the section on known difference between boost::result_of and > TR1 in the documentation.)
The rationale for this always confused me, with the end result (it seems) that it makes TR1 result_of basically unusable for nullary function calls.
result_type is consulted. result<> is not. type is void (instead of a compile error) when there is no result_type.
The reason for the type being void is that in
template<class T> class reference_wrapper { private:
T & t_;
public:
typename result_of
::type operator()() const { return t_(); } }; operator()() is not a template. If result_of
::type wasn't present or generated an error when T doesn't have result<>, reference_wrapper<int> would have generated an error when instantiated. In C++11, you can make operator()() a template. In C++03, you can't.
Thanks Peter. I forgot that you can still use result_type with nullary functors. I feel like I haven't used TR1 in a while... - Daniel