
7 Apr
2008
7 Apr
'08
6:31 a.m.
Eric Niebler wrote:
Let me clarify. This identity implementation is simply wrong (if you pass an rvalue to identity.) because of inconsistency between decltype and result_of. Am I missing anything?
I don't think so. If I have an rvalue, I compute the return type and invoke the function as follows:
result_of<identity(int)>::type i = identity()(1);
This is perfectly safe. If I have an lvalue, it looks like this:
int const i = 0; result_of<identity(int const &)>::type j = identity()(i);
Also perfectly safe.
Hmm, result_of must be consistent with decltype, IMO. It seems not "safety" but "mathematics". :-) How about this? : result_of<identity(int)>::type // doh in C++0x. test() { return identity()(3); } Regards, -- Shunsuke Sogame