Re: Public and private versions of opIndex

2021-07-01 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 1 July 2021 at 20:23:41 UTC, Ben Jones wrote: I tried to to write 2 versions of opIndex: ``` public Type opIndex(IndexType x) const {... } //and private Type ref opIndex(IndexType x) { ... } ``` which doesn't seem to work because client code that has a non-const reference to my

Public and private versions of opIndex

2021-07-01 Thread Ben Jones via Digitalmars-d-learn
I have a struct which I would like to have a public opIndex which returns by value (so client code can't modify my internal array), and a private version which allows the implementing code to modify stuff with `this[whatever] = whatever`. I tried to to write 2 versions of opIndex: ``` public