Boost logo

Boost :

Subject: Re: [boost] lifetime of ranges vs. iterators
From: David Abrahams (dave_at_[hidden])
Date: 2008-09-05 12:55:51


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

>> You're completely right about that, and there are even additional
>> reasons that you didn't mention, as I realized a couple days ago. I
>> didn't want to bring it up, though, because it doesn't change the
>> fundamental reality. Just replace strided_iterator by another layer of
>> filter_iterator.
>
> Hum, but as long as an iterator contains only a range, you can always
> encapsulate it with no space overhead. a
> filter_iterator<filter_iterator<T* > > has sizeof(T*2) (assuming a
> stateless predicate), which is optimal.

First of all, there's other kinds of data that's redundant across pairs
of iterators in a range hey, like the predicate!

But let's ignore that for a moment. The range compression formula is:

      sizeof(range<X>) == 2*sizeof(X) - sizeof(common_data<X>::type)

    so when X is filter_iterator<Y>:

       sizeof(X) is 2*sizeof(Y)
       common_data<X>::type == Y

    so:

       sizeof(range<X>) == 2*(2*sizeof(Y)) - sizeof(Y) == 3*sizeof(Y)

    so if sizeof(filter_iterator<Y>) == sizeof(range<Y>)

       sizeof(filter_iterator<Y>)
       == sizeof(range<Y>)
       == 2*sizeof(Y) - sizeof(common_data<Y>::type)

    and when Y is filter_iterator<Z>,
    X is filter_iterator<filter_iterator<Z> >

       sizeof(Y) is 2*sizeof(Z)
       common_data<Y>::type == Z

    so:

       sizeof(range<Y>) == 2*(2*sizeof(Z)) - sizeof(Z) == 3*sizeof(Z)
       sizeof(filter_iterator<Y>) == 3*sizeof(Z)
       sizeof(range<X>) == 3*sizeof(Y) == 3*2*sizeof(Z) == 6*sizeof(Z)

What am I missing?

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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