Are iterators and ranges going to co-exist?

Steven Schveighoffer schveiguy at yahoo.com
Thu Jul 22 04:19:28 PDT 2010


On Wed, 21 Jul 2010 17:00:35 -0400, Michel Fortin  
<michel.fortin at michelf.com> wrote:

> On 2010-07-21 13:00:56 -0400, Peter Alexander  
> <peter.alexander.au at gmail.com> said:
>
>> An example of an algorithm that would take a cursor is
>> insertBefore. There is no reason for it to accept a range, because
>> you are not traversing elements. You just want to insert something
>> before some single point in the range.
>
> From what I understand, you'd like something like this to work:
>
> 	auto range = container[];
> 	auto sortOfIterator = range.front;
> 	container.insertBefore(sortOfIterator);

 From dcollections:

auto range = container[];
auto cursor = range.begin;
container.insert(cursor, value);

Note that insertBefore is reduced to insert, because the ambiguity is gone  
(there is only one element in a cursor, so it's obvious where you are  
inserting).

-Steve


More information about the Digitalmars-d mailing list