Iterators for D
Walter Bright
newshound at digitalmars.com
Mon Nov 6 19:00:12 PST 2006
Jarrett Billingsley wrote:
> "Walter Bright" <newshound at digitalmars.com> wrote in message
> news:eio6u5$1j6o$1 at digitaldaemon.com...
>
>> Overload opIndex for rvalue access
>> Overload opIndexAssign for lvalue access
>
> Somehow..
>
> foreach(i; foo)
> {
> auto x = i[0];
> i[0] = x + 1;
> }
>
> You often say that operator overloading should be used only what it should
> be used for, and taking the index of an iterator means.. what exactly?
>
> Would it be nicer to just use a .value property instead?
>
> foreach(i; foo)
> {
> auto x = i.value;
> i.value = x + 1;
> }
The problem is if the iterator is an actual pointer, there is no .value
property for a pointer.
Another possibility is to have:
*x
rewritten to:
x[0]
if x is not a pointer.
More information about the Digitalmars-d
mailing list