|
Boost : |
From: Doug Gregor (dgregor_at_[hidden])
Date: 2007-01-08 10:40:20
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:
>
> http://tinyurl.com/yzeenu
>
> 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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk