[tr1/result of] and l/r values

Hi, here's another result_of question: Given a function object struct f { template< typename T > r<T> operator()(T const &) const; template< typename T > r<T&> operator()(T &) const; template< typename Sig > struct result; }; , result_of< f(some_obj &) >::type // is r<T&> result_of< f(some_obj const & >::type // is r<T> but what about: result_of< f(some_obj) >::type // is r<T>? That's what I'd do intuitively. I also found an example (written by Dave) on the net that seems to do the same: http://tinyurl.com/yzeenu But wait: the TR1 text is talking about lvalues so I probably should let F::result return r<T&>?! Thanks a lot for clarification. Regards, Tobias

On Dec 27, 2006, at 7:55 AM, Tobias Schwinger wrote:
here's another result_of question:
Given a function object
struct f { template< typename T > r<T> operator()(T const &) const;
template< typename T > r<T&> operator()(T &) const;
template< typename Sig > struct result; };
,
result_of< f(some_obj &) >::type // is r<T&> result_of< f(some_obj const & >::type // is r<T>
but what about:
result_of< f(some_obj) >::type // is r<T>?
Yes, that's right.
That's what I'd do intuitively. I also found an example (written by Dave) on the net that seems to do the same:
But wait: the TR1 text is talking about lvalues so I probably should let F::result return r<T&>?!
TR1 says... Given an rvalue f of type F and values t1, t2, ..., tN of types T1, T2, ..., TN, respectively, the type member is the result type of the expression f(t1, t2, ...,tN). The values ti are lvalues when the corresponding type Ti is a reference type, and rvalues otherwise. So with result_of< F(some_obj)>, we treat some_obj as an rvalue, and get the same result as for result_of< f(some_obj const & >. Cheers, Doug

Doug Gregor wrote:
On Dec 27, 2006, at 7:55 AM, Tobias Schwinger wrote:
here's another result_of question:
Given a function object
struct f { template< typename T > r<T> operator()(T const &) const;
template< typename T > r<T&> operator()(T &) const;
template< typename Sig > struct result; };
,
result_of< f(some_obj &) >::type // is r<T&> result_of< f(some_obj const & >::type // is r<T>
but what about:
result_of< f(some_obj) >::type // is r<T>?
Yes, that's right.
That's what I'd do intuitively. I also found an example (written by Dave) on the net that seems to do the same:
But wait: the TR1 text is talking about lvalues so I probably should let F::result return r<T&>?!
TR1 says...
Given an rvalue f of type F and values t1, t2, ..., tN of types T1, T2, ..., TN, respectively, the type member is the result type of the expression f(t1, t2, ...,tN). The values ti are lvalues when the corresponding type Ti is a reference type, and rvalues otherwise.
Sorry - it seems I missed that last part of the sentence, somehow (maybe by looking at the wrong version?).
So with result_of< F(some_obj)>, we treat some_obj as an rvalue, and get the same result as for result_of< f(some_obj const & >.
OK, got it. Thank you! Regards, Tobias

On Jan 8, 2007, at 11:32 AM, Tobias Schwinger wrote:
Doug Gregor wrote:
TR1 says...
Given an rvalue f of type F and values t1, t2, ..., tN of types T1, T2, ..., TN, respectively, the type member is the result type of the expression f(t1, t2, ...,tN). The values ti are lvalues when the corresponding type Ti is a reference type, and rvalues otherwise.
Sorry - it seems I missed that last part of the sentence, somehow (maybe by looking at the wrong version?).
It's likely that you were looking at an older draft of TR1. We had originally said that everything was an lvalue. We later realized that making them rvalues by default, with references signifying lvalues, gave us a more functional result_of that was actually easier to deal with. The final TR1 draft and the C++0x draft have the revised wording I quoted. Cheers, Doug

On Jan 8, 2007, at 11:48 AM, Doug Gregor wrote:
On Jan 8, 2007, at 11:32 AM, Tobias Schwinger wrote:
Doug Gregor wrote:
TR1 says...
Given an rvalue f of type F and values t1, t2, ..., tN of types T1, T2, ..., TN, respectively, the type member is the result type of the expression f(t1, t2, ...,tN). The values ti are lvalues when the corresponding type Ti is a reference type, and rvalues otherwise.
Sorry - it seems I missed that last part of the sentence, somehow (maybe by looking at the wrong version?).
It's likely that you were looking at an older draft of TR1. We had originally said that everything was an lvalue. We later realized that making them rvalues by default, with references signifying lvalues, gave us a more functional result_of that was actually easier to deal with. The final TR1 draft and the C++0x draft have the revised wording I quoted.
We have the same issue with is_convertible (the From parameter). I hope to fix it the same way: http://home.twcny.rr.com/hinnant/cpp_extensions/type_traits_changes.html#rel -Howard
participants (4)
-
Doug Gregor
-
Howard Hinnant
-
Tobias Schwinger
-
Tobias Schwinger