nested inout return type

Era Scarecrow via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 13 18:50:17 PDT 2016


On Monday, 13 June 2016 at 23:51:40 UTC, Era Scarecrow wrote:
>      inout(Slice) opSlice(size_t a, size_t b) inout
>      {
>          return cast(inout(Slice)) Slice(ptr+a, b-a);
>      }

  Seems the pointer has to be force-cast back to a normal pointer 
so the constructor can work. (Because the function is inout, ptr 
becomes inout(T*) )

      return cast(inout(Slice)) Slice(cast(T*)ptr+a, b-a);

  Beyond that it works as expected :) Writeln gives the following 
output on Slice with opSlices:

Slice!int(18FD60, 10)
const(Slice!int)(18FD60, 10)
immutable(Slice!int)(18FD90, 10)


More information about the Digitalmars-d-learn mailing list