Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2007-11-21 21:31:39

Joel de Guzman wrote:
> shunsuke wrote:
>> Joel de Guzman wrote:
>>> shunsuke wrote:
>>>> Hi,
>>>> I'm trying to fix ticket #1396:
>>>> Any hint?
>>> I just replied to that in the ticket :-) HTH.
>> Hmm, your `identity` implementation seems wrong.
>> `result<Fun(int)>` invocation means that the argument is rvalue
>> by the definition of result_of behavior.
>> Therefore, you can't return mutable reference to `int`.
> Well, it's just for that specific case. Did you intend the
> transform to be generic? I didn't think so when you had
> it hard coded to int. I guess, it really depends on what
> your intent is. A transform cannot, in general, return a
> reference. What if the input is computed on the fly,
> like, say:
> mpl::vector_c<int, 1, 2, 3>

Here's a more generic identity transform that works for
mpl sequences too, FWIW (attached test in the trac ticket):

struct identity
     template<class FunCall>
     struct result;

     template <class Fun, class T>
     struct result<Fun(T)>
         typedef T type;

     template <class T>
     T& operator()(T& val) const
         return val;

     template <class T>
     T const& operator()(T const& val) const
         return val;


Joel de Guzman

Boost list run by bdawes at, gregod at, cpdaniel at, john at