Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2008-04-07 07:29:50


> shunsuke wrote:
>> Eric Niebler wrote:
>>> I think that's right so far. Now imagine a simple identity function
>>> object, that just returns its argument unmodified:
>>>
>>> struct identity
>>> {
>>> template<typename Sig>
>>> struct result;
>>>
>>> template<typename This, typename Arg>
>>> struct result<This(Arg)>
>>> {
>>> typedef Arg type;
>>> };
>>>
>>> template<typename Arg>
>>> Arg const &operator()(Arg const &arg)
>>> {
>>> return arg;
>>> }
>>>
>>> // and a non-const overload, too
>>> };
>>
>> Let me clarify.
>> This identity implementation is simply wrong (if you pass an rvalue to
>> identity.)
>> because of inconsistency between decltype and result_of.

Yes, it's wrong, result<> and operator() are out of sync.
result_of<identity(X&)>::type returns X&, whereas identity()(x), where x is
an lvalue of type X, returns X const&.

    Arg& operator()( Arg& ) const;
    Arg operator()( Arg const& ) const;

maybe? I still don't remember how these overloads are resolved for a const
lvalue. Either way, this seems the best we can do in C++03.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk