When to opCall instead of opIndex and opSlice?
Per Nordlöw
per.nordlow at gmail.com
Mon Oct 2 18:31:23 UTC 2017
On Monday, 2 October 2017 at 18:14:24 UTC, Jacob Carlborg wrote:
> On 2017-10-02 17:57, Nordlöw wrote:
>> Is implementing opCall(size_t) for structures such as array
>> containers that already define opIndex and opSlice deprecated?
>>
>> I can't find any documentation on the subject on when opCall
>> should be defined to enable foreach (isIterable).
>
> opCall is not related to foreach. It's used to overload the
> call operator, i.e. ().
>
> struct Foo
> {
> void opCall() {};
> }
>
> Foo foo;
> foo();
>
> Are you thinking of opApply [1]?
>
> [1]
> https://dlang.org/spec/statement.html#foreach_over_struct_and_classes
Ahh, yes of course.
It seems like defining opIndex anf opSlice is enough in the array
container case. Why do we have opApply as well? Non-random access?
More information about the Digitalmars-d-learn
mailing list