Thorsten Ottosen | 4 Sep 09:36

[iterator] could non-small predicates/functors be stored as boost::optional<T> to avoid double construction?

Hi,

The headline pretty much says it all. Take transform iterator. When the 
predicate is not trivial, we also have a redundant construction of the 
object in the end iterator. Maybe that could be removed?

best regards

-Thorsten
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Arno Schödl | 4 Sep 14:09
Favicon

Re: [iterator] could non-small predicates/functors be stored as boost::optional<T> to avoid double construction?

> Hi,

> The headline pretty much says it all. Take transform iterator. When the 
> predicate is not trivial, we also have a redundant construction of the 
> object in the end iterator. Maybe that could be removed?

> best regards

> -Thorsten

I guess that would be restricted to forward iterators.

Arno

--
Dr. Arno Schoedl · aschoedl <at> think-cell.com 
Technical Director 

think-cell Software GmbH · Invalidenstr. 34 · 10115 Berlin, Germany 
http://www.think-cell.com · phone +49-30-666473-10 · toll-free (US) +1-800-891-8091
Directors: Dr. Markus Hannebauer, Dr. Arno Schoedl · Amtsgericht Charlottenburg, HRB 85229

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Thorsten Ottosen | 4 Sep 15:47

Re: [iterator] could non-small predicates/functors be stored as boost::optional<T> to avoid double construction?

Arno Schödl skrev:
>> Hi,
> 
>> The headline pretty much says it all. Take transform iterator. When the 
>> predicate is not trivial, we also have a redundant construction of the 
>> object in the end iterator. Maybe that could be removed?
> 
>> best regards
> 
>> -Thorsten
> 
> I guess that would be restricted to forward iterators.

This has nothing to do with the wrapped iterator's type. A transform 
iterator currently stores a functor by value in addition to the wrapped 
iterator.

-Thorsten
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
David Abrahams | 4 Sep 16:08
Favicon
Gravatar

Re: [iterator] could non-small predicates/functors be stored as boost::optional<T> to avoid double construction?


on Thu Sep 04 2008, Thorsten Ottosen <thorsten.ottosen-AT-dezide.com> wrote:

> Arno Schödl skrev:
>>> Hi,
>>
>>> The headline pretty much says it all. Take transform iterator. When the
>>> predicate is not trivial, we also have a redundant construction of the object
>>> in the end iterator. Maybe that could be removed?
>>
>>> best regards
>>
>>> -Thorsten
>>
>> I guess that would be restricted to forward iterators.
>
> This has nothing to do with the wrapped iterator's type. A transform iterator
> currently stores a functor by value in addition to the wrapped iterator.

Have you forgotten

  *--end

?
--

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
(Continue reading)

Thorsten Ottosen | 4 Sep 20:18

Re: [iterator] could non-small predicates/functors be stored as boost::optional<T> to avoid double construction?

David Abrahams skrev:
> on Thu Sep 04 2008, Thorsten Ottosen <thorsten.ottosen-AT-dezide.com> wrote:
> 
>> Arno Schödl skrev:
>>>> Hi,
>>>> The headline pretty much says it all. Take transform iterator. When the
>>>> predicate is not trivial, we also have a redundant construction of the object
>>>> in the end iterator. Maybe that could be removed?
>>>> best regards
>>>> -Thorsten
>>> I guess that would be restricted to forward iterators.
>> This has nothing to do with the wrapped iterator's type. A transform iterator
>> currently stores a functor by value in addition to the wrapped iterator.
> 
> Have you forgotten
> 
>   *--end

Yes. Sorry for the noise.

-Thorsten

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Re: [iterator] could non-small predicates/functors be stored as boost::optional<T> to avoid double construction?

On Thu, Sep 4, 2008 at 8:18 PM, Thorsten Ottosen
<thorsten.ottosen <at> dezide.com> wrote:
> David Abrahams skrev:
>>
>> on Thu Sep 04 2008, Thorsten Ottosen <thorsten.ottosen-AT-dezide.com>
>> wrote:
>>
>>> Arno Schödl skrev:
>>>>>
>>>>> Hi,
>>>>> The headline pretty much says it all. Take transform iterator. When the
>>>>> predicate is not trivial, we also have a redundant construction of the
>>>>> object
>>>>> in the end iterator. Maybe that could be removed?
>>>>> best regards
>>>>> -Thorsten
>>>>
>>>> I guess that would be restricted to forward iterators.
>>>
>>> This has nothing to do with the wrapped iterator's type. A transform
>>> iterator
>>> currently stores a functor by value in addition to the wrapped iterator.
>>
>> Have you forgotten
>>
>>  *--end
>
> Yes. Sorry for the noise.
>

(Continue reading)

David Abrahams | 4 Sep 21:07
Favicon
Gravatar

Re: [iterator] could non-small predicates/functors be stored as boost::optional<T> to avoid double construction?


on Thu Sep 04 2008, "Giovanni Piero Deretta" <gpderetta-AT-gmail.com> wrote:

> On Thu, Sep 4, 2008 at 8:18 PM, Thorsten Ottosen
> <thorsten.ottosen <at> dezide.com> wrote:
>> David Abrahams skrev:
>>>
>>> on Thu Sep 04 2008, Thorsten Ottosen <thorsten.ottosen-AT-dezide.com>
>>> wrote:
>>>
>>>> Arno Schödl skrev:
>>>>>>
>>>>>> Hi,
>>>>>> The headline pretty much says it all. Take transform iterator. When the
>>>>>> predicate is not trivial, we also have a redundant construction of the
>>>>>> object
>>>>>> in the end iterator. Maybe that could be removed?
>>>>>> best regards
>>>>>> -Thorsten
>>>>>
>>>>> I guess that would be restricted to forward iterators.
>>>>
>>>> This has nothing to do with the wrapped iterator's type. A transform
>>>> iterator
>>>> currently stores a functor by value in addition to the wrapped iterator.
>>>
>>> Have you forgotten
>>>
>>>  *--end
>>
(Continue reading)

Steven Watanabe | 4 Sep 21:32

Re: [iterator] could non-small predicates/functors be stored as boost::optional<T> to avoid double construction?

AMDG

David Abrahams wrote:
>> 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.
>>     
>
> But for that you wouldn't need the bool in optional.
>   

I think that you do need it, actually.
I assume that assignment would be implemented with destroy + reconstruct?
In this case, you need to deal with the possibility of the copy 
constructor throwing.

In Christ,
Steven Watanabe

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

David Abrahams | 4 Sep 15:58
Favicon
Gravatar

Re: [iterator] could non-small predicates/functors be stored as boost::optional<T> to avoid double construction?


on Thu Sep 04 2008, Thorsten Ottosen <thorsten.ottosen-AT-dezide.com> wrote:

> Hi,
>
> The headline pretty much says it all. Take transform iterator. When the
> predicate is not trivial, we also have a redundant construction of the object in
> the end iterator. Maybe that could be removed?

It would increase the overall size because optional<T> needs to store a
bool as well as a T.  It would work for any kind of iterator traversal
because the function object would need to be constructed on demand (you
have to do that even for forward iterators because you can't know that
the end iterator of a range isn't known by the user to be somewhere in a
larger range -- the user can always dereference it in that case), but
that extra check upon dereference would also increase cost.  I am not
really convinced it's worthwhile.

--

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Gmane