nested inout return type

Era Scarecrow via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 14 12:38:01 PDT 2016


On Tuesday, 14 June 2016 at 14:47:11 UTC, Steven Schveighoffer 
wrote:
>> On Tuesday, 14 June 2016 at 01:50:17 UTC, Era Scarecrow wrote:
>>>      return cast(inout(Slice)) Slice(cast(T*)ptr+a, b-a);
>
> Better: inout(Slice)(ptr+a, b-a);

  Of course... My amateur D-fu skills show themselves. cast() 
const() immutable() are the same, why not inout? Hmmm...

  Reminds me when I didn't understand how to get the address or 
use pointers correctly, so I'd do stuff like &ptr[i] everywhere 
because no one told me a better way to do it.

  I also remember seeing odd issues and bugs in C when using a 
char and then having negative numbers so having to use & 0xff 
flags everywhere until I added the _unsigned_ keyword in.

  I feel like a tutorial for common problems and solutions should 
be present for C, C++ & D. Then again maybe that's some cookbooks 
that I haven't purchased/read yet.


More information about the Digitalmars-d-learn mailing list