nested inout return type

Simon Bürger via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 13 15:31:00 PDT 2016


I'm writing a custom (originally multi-dimensional) Slice-type, 
analogous to the builtin T[], and stumbled upon the problem that 
the following code won't compile. The workaround is simple: just 
write the function three times for mutable/const/immutable. But 
as "inout" was invented to make that unneccessary I was wondering 
if there is a clever way to make this work.


struct Slice(T)
{
     T* ptr;
     size_t length;

     Slice!(inout(T)) opSlice(size_t a, size_t b) inout
     {
         return Slice!(inout(T))(ptr+a, b-a);
     }
}


More information about the Digitalmars-d-learn mailing list