Methods that work for both mutable and immutable objects in D

I am trying to write an access method for a class in D that I want to use for mutable and immutable instances.

public immutable(double[]) getInputs(uint i)immutable{
  return this.data[i];
}
public double[] getInputs(uint i){
  return this.data[i];
}

I keep getting compiler errors if I don't do both of these versions that (almost) do the same.

Since I am not changing any state, is it possible to use a single method that works on both mutable and immutable instances?

+4
source share
1 answer

D has inoutfor this:

public inout(double[]) getInputs(uint i) inout
{
    return this.data[i];
}

, (this) const, immutable (). , this.

. inout-.

+4

All Articles