Subject: Re: [boost] [iterator] could non-small predicates/functors be stored as boost::optional<T> to avoid double construction?
From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2008-09-04 14:33:21
On Thu, Sep 4, 2008 at 8:18 PM, Thorsten Ottosen
> David Abrahams skrev:
>> on Thu Sep 04 2008, Thorsten Ottosen <thorsten.ottosen-AT-dezide.com>
>>> Arno Schödl skrev:
>>>>> The headline pretty much says it all. Take transform iterator. When the
>>>>> predicate is not trivial, we also have a redundant construction of the
>>>>> in the end iterator. Maybe that could be removed?
>>>>> best regards
>>>> I guess that would be restricted to forward iterators.
>>> This has nothing to do with the wrapped iterator's type. A transform
>>> currently stores a functor by value in addition to the wrapped iterator.
>> Have you forgotten
> Yes. Sorry for the noise.
There is still some value in storing functors in optional<T>:
boost.lambda expressions are not asignable, thus rendering any
iterator that contains a lambda does no longer meet the requirements
of Assignable of which TrivialIterator is a refinement of.
It is easy to add a wrapper around optional<T> that makes it
Assignable as long as T is copy constructible (which lambdas are), so
it can be used as a quick workaround for this problem.
Many algorithms do not actually require assignability, so I do not
think it is worth to explicitly workaround boost lambda in every
iterator. Some external mean is better. Egg for example had a
'regular' function which wrapped a lambda in an optional on the fly.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk