Returning range of inout objects from inout method

FreeSlave freeslave93 at gmail.com
Sat Jul 25 12:26:52 UTC 2020


I want to be able to return a range of const objects from the 
const object and a range mutable objects from the mutable object.

inout comes to mind, but not applicable in this case, because 
inout must be applied to the return type as whole, which does not 
make much sense for the range. Defining range of inout objects 
does not work too. See the example.

import std.range;
class A
{
     string name;
}

class B
{
     A[] _actions;
     ForwardRange!(inout(A)) byAction() inout { // can't instance 
this type
         import std.algorithm : filter;
         return inputRangeObject(_actions.filter!(a => a !is null 
&& a.name.length));
     }
}

So how can I achieve the intended effect without code 
duplication? (like making separate mutable and const versions of 
the method).


More information about the Digitalmars-d-learn mailing list