May 11, 2009
On Sat, 09 May 2009 12:40:34 -0400, Michel Fortin <michel.fortin@michelf.com> wrote:

> On 2009-05-09 10:45:05 -0400, "Steven Schveighoffer" <schveiguy@yahoo.com> said:
>
>> STL iterators can be used for more than just iteration.  They also serve  as cursors, or pointers to specific elements.  If you add the ability for  them to check their own bounds, then they become as safe as ranges, and  can be used as general purpose pointers for things like insertion,  deletion, bi-directional traversal, things that ranges can do but are  clumsy at.
>>  You still have the interchangable-with-pointer concept burned into your  brain :)
>>  Think more like this:
>>  for(cursor i = begin; !i.end; i++)
>
> So basically your cursor is a range (so it knows its bounds) with an added position pointer.

Basically, yes.

-Steve
May 11, 2009
On Sat, 09 May 2009 22:10:22 -0400, Rainer Deyke <rainerd@eldwood.com> wrote:

> dsimcha wrote:
>> == Quote from Rainer Deyke (rainerd@eldwood.com)'s article
>>> Although I like ranges, it looks to me like there are a couple of
>>> operations that would difficult to implement without iterators or some
>>> other way to specify a specific position in a range.
>>> Finding and erasing an element:
>>>   list.erase(find(list.begin(), list.end(), e));
>>
>> What's wrong with this?  Since list owns its range representation, it can know the
>> implementation details.  For a linked list, this will probably be just a pair of
>> pointers under the hood anyhow.  In other words, it's internally still an
>> iterator, just prettier looking.
>
> The following is semantically incorrect:
>   r = find(list, e)
>   list.erase(r)
>
> 'find' advances only the front of the range to the found element.
> Therefore 'r' is the range of all elements starting with the found
> element, but also including all elements after that.
>
> I would expect 'list.erase(range)' to erase all elements in the range.
> However, in this case I only want to erase a single element.  This could
> still be expressed with ranges, but it would require a different
> function.  For example:
>   find(list, e).eraseFront()
> Or:
>   list.eraseFrontOf(find(list, e))
> Or:
>   list.eraseOne(find(list, e))
> Or:
>   list.findAndErase(e)
> Or:
>   list.erase(take(1, find(list, e)))

I think Andrei's plans are for this last one.  You can srhink a range, so use the range primitives to srhink it to a 1-element range, then call erase.

>>> Splitting a container on a position:
>>>   iter = find(list.begin(), list.end(), e);
>>>   do_something_with(list.begin(), iter);
>>>   do_something_else_with(iter, list.end());

From what I remember from the earlier discussions, Andrei's plan is for you to be able to subrange a range.  So for example, you have 2 ranges that overlap, return a range that is the intersection or complement.

I don't have huge issues with that solution, but I would point out that you now are depending on the developer to ensure the ranges do in fact overlap.  Of course, I could be wrong with my assumption (about Andrei's intent), maybe he has a better solution.

-Steve
1 2 3
Next ›   Last »