Are iterators and ranges going to co-exist?
Michel Fortin
michel.fortin at michelf.com
Wed Jul 21 14:00:35 PDT 2010
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);
Couldn't this be acheived with a 'smart reference' struct? Something like this:
struct SmartRef(T) {
ref T value() { return *data.ptr; }
alias value this;
private:
SortOfIteratorData data;
}
Then you define front (and any function normally returning a reference) as:
SmartRef!T front();
and it should work as usual, in addition to carrying the extra data you
want in your 'iterator'.
It's totally transparent (as long as the user uses 'auto' for its
references), but it's more burden to the implementor.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list