The difference between T[] opIndex() and T[] opSlice()

Paul Backus snarwin at gmail.com
Mon Oct 2 20:42:14 UTC 2023


On Monday, 2 October 2023 at 20:34:11 UTC, Salih Dincer wrote:
> In an old version (for example, v2.0.83), the code you 
> implemented in the places where Slice is written above works as 
> desired.  In the most current versions, the parameterized 
> opIndexAssign(T value) gives the error:
>
>> onlineapp.d(51): Error: function 
>> `onlineapp.Matrix!double.Matrix.opIndexAssign(double value)` 
>> is not callable using argument types `(double, ulong)`
>> onlineapp.d(51):        expected 1 argument(s), not 2
>
> **Source:** https://run.dlang.io/is/TPAg5m

I don't know what's wrong in your example but this works for me:

```d
struct S
{
     void opIndexAssign(int value)
     {
         import std.stdio;
         writeln("assigned ", value);
     }
}

void main()
{
     S s;
     s[] = 7;
}
```


More information about the Digitalmars-d-learn mailing list