Discussion Thread: DIP 1035-- at system Variables--Community Review Round 2

Paul Backus snarwin at gmail.com
Fri Feb 26 13:49:52 UTC 2021


On Friday, 26 February 2021 at 09:49:40 UTC, Walter Bright wrote:
>     private static struct Slice
>     {
>         private int* ptr;
>         private size_t length;
>
>       @trusted:
>
>         this(int[] src)
>         {
>              ptr = src.ptr;
>              length = src.length;
>         }
>
>         int[] opSlice()
>         {
>              return ptr[0 .. length];
>         }
>      }

This is equivalent to the example in the DIP, except that you 
have changed the constructor from @safe to @trusted by replacing 
`&src[0]` with `src.ptr`. If you had written it in the same was 
as the original, you would still have to manually check @safe 
code in order to prove that this interface is memory-safe.


More information about the Digitalmars-d mailing list