Chaining opIndex

deed via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 10 05:34:32 PDT 2016


On Monday, 9 May 2016 at 22:33:37 UTC, John Colvin wrote:
> There are lots of ways to approach this. Here's one possibility:
>
> auto cars(Bar bar)
> {
>     static struct Res
>     {
>         Bar bar;
>         Car opIndex(size_t i)
>         {
>             return /* e.g. getCar(bar, i); */
>         }
>     }
>     return Res(bar);
> }

Thanks. Didn't think of function returning struct with opIndex. 
Having this as opCall in a struct Cars might be a solution.

What other approaches did you have in mind?


More information about the Digitalmars-d-learn mailing list