From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2007-08-11 10:58:51
On 8/10/07, shunsuke <pstade.mb_at_[hidden]> wrote:
> Giovanni Piero Deretta wrote:
> >> Also note that Boost.Lambda can't be used here.
> >> A Boost.Lambda functor is not Assignable.
> > Yes, that is very unfortunate and I think it should be fixed.
> > I saw that oven uses a special wrapper to make boost.lambda objects
> > copiable. What does it exactly do?
> As you guess, the wrapper uses Boost.Optional.
> It's rather simple: http://tinyurl.com/2nvw59
> > The wrapper I use simply does a placement new in its assignment operator.
> > This is very exception unsafe, but I presume that most (all?) lambda
> > objects won't throw
> > on copy constructor. Using boost.optional would give the basic
> > exception safetly, but it does increase the size of the wrapper.
> I'm not sure.
> Boost.Optional also seems to use placement-new.
Yes, but it also need a boolean to record the initialized/non initialized state.
In this case, if you assume that copyconstruction of a lambda never
throws (a strong assumption, but it works in my case), you can do
without the bolean. My range expressions are growing larger and larger
even without the extra bool :)
> Anyway, Boost.Optional seems fundamental,
> because Boost.Lambda functors are not DefaultConstructible,
> which ForwardIterator requires.
Hum,. you are right. Probably I've just been lucky and never used an
algo that needed
to default construction of my iterators so far. I'll probably revert
my code to use optional.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk