opIndexDispatch?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 14 07:31:23 PDT 2016


On Friday, October 14, 2016 09:09:33 Marc Schütz via Digitalmars-d-learn 
wrote:
> On Thursday, 13 October 2016 at 01:09:06 UTC, Ali Çehreli wrote:
> > On 10/10/2016 12:01 PM, Yuxuan Shui wrote:
> >> Hi,
> >>
> >> Why is there no opIndexDispatch for overloading a[x].func() ?
> >
> > I could not understand the question fully but would using an
> > element proxy work?
>
> I assume a proxy would indeed work, but it's indeed inconsistent.
> A proxy would work for opIndexAssign() and friends as well, so
> why do they exist, when opIndexDispatch() doesn't?

Presumably, because it  didn't occur to anyone when the others were added.
And most stuff implementing opIndex is likely to have it return by ref. But
opDispatch is kind of a weird beast to begin with. There are a few cases
where it's really useful, but in general, it's not used much. And I'm pretty
sure it's one of the overloaded operators that was added later on given that
most of them existed in different forms before we used templated functions
with strings for overloaded operators, whereas opDispatch requires a
compile-time string. So, when the decision to add the opIndex* functions in
addition to opIndex was made, opDispatch probably hadn't even been proposed
yet.

- Jonathan M Davis




More information about the Digitalmars-d-learn mailing list