Safe Cursors and Ranges

Pillsy pillsbury at gmail.com
Thu Aug 26 08:17:32 PDT 2010


Steven Schveighoffer Wrote:

> On Thu, 26 Aug 2010 10:18:51 -0400, Pillsy <pillsbury at gmail.com> 
> wrote:
[...]
> > The key idea is that these cursors aren't a primitive part of a
> > range; instead, they take a range and add a position *inside* 
> > the range. They're a perfect fit for all those "three-legged" 
> > operations out there because they actually have three legs.
[...]
> The 'three-legged' cursor as you propose was an early idea of
> mine too. 

If you don't mind me asking, what made you give up on it? 

> My view is that a cursor should be separate from a range, and a
> range should either be able to tell if a cursor is part of it (@safe)
> or be told  that a cursor is a part of it (@system or @trusted).  

What's the advantage of not holding on to the range as part of the 
cursor? I'm more focused on the typical value-type ranges, but I'm 
not seeing a lot of need for cursors that have lives independent of 
underlying ranges. Is the concern just one of more frequent 
invalidation? 

IME, three-legged operations are fairly common, but four- and more-
legged operations which can't be easily decomposed into consecutive 
three-legged operations are very uncommon. 

What I'm thinking is that cursors aren't skinny ranges, they're ranges 
that are even fatter. You simply wouldn't use one where a range 
would suffice. Allowing questions about whether a range contains a 
cursor or not strikes me as just buying trouble.

Thanks for your thoughts,
Pillsy


More information about the Digitalmars-d mailing list