array inside a class + alias this + filter -> clears the array.

realhet real_het at hotmail.com
Wed Jul 7 18:17:29 UTC 2021


On Wednesday, 7 July 2021 at 17:10:01 UTC, Paul Backus wrote:
> On Wednesday, 7 July 2021 at 16:20:29 UTC, realhet wrote:

>     int[] opIndex() { return array; }

Thx, I didn't know about this type of opSlice override. It works 
nicely.

Now I have these choices:
- write [] everywhere to access the containers.
- write nothing extra to access the containers but put the 
container operations one level higher and select the container 
for those based on a dummy struct.

Like going from:
```
db.entities.add("Entity01");
to
db.add(entity("Entity01"));   //struct entity{ string name; }
```

Currently I have both ways plus your solution for the range 
access.

Gotta experience with it to choose.

Thanks again! I will remember that common container rule from now 
on.


More information about the Digitalmars-d-learn mailing list