When to opCall instead of opIndex and opSlice?
Jacob Carlborg
doob at me.com
Mon Oct 2 18:14:24 UTC 2017
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
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list