Boost logo

Boost :

From: Felipe Magno de Almeida (felipe.m.almeida_at_[hidden])
Date: 2008-04-10 01:05:38


On Wed, Apr 9, 2008 at 11:11 PM, shunsuke <pstade.mb_at_[hidden]> wrote:
> Eric Niebler wrote:
> > Anyway, about the rvalue_wrapper<> Shunsuke proposed and I just
> > endorsed. The issue is that today, users are writing code like this:
> >
> > int const i = 0;
> > fusion::tuple<int> t = fusion::make_tuple(i);
> >
> > This is arguably wrong because it is storing an lvalue by value. This is
> > probably more correct:
> >
> > int const i = 0;
> > fusion::tuple<int const &> t = fusion::make_tuple(i);
>
> It seems to depend on context or domain.
> Proto may expect it, but
>
> int const i = 0;
> return fusion::make_tuple(i);
>
> would be "ouch".

Also would be "ouch" for:

struct handler
{
  typedef void result_type;
  result_type operator()(int i) const
  {
  }
};

int const i = 0;
sock_->async_read( buffer, fusion::fused(handler(), fusion::make_vector(i)) );

> BTW, Egg offers "pack", which captures all the arguments by-reference.

I prefer by-value by default. Afterall, C++ is a value-based language.

[snip]

> As shown above, lvalue/rvalue-ness doesn't guarantee the complete safety.
> FWIW, I usually prefer compatibility. :-)

I would say lvalue/rvalue-ness are safe only when used for reusing temporaries.

> Regards,
> --
> Shunsuke Sogame

Regards,

-- 
Felipe Magno de Almeida

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