can we un-deprecate .ptr on arrays in @safe code? cf issue 18529

Steven Schveighoffer schveiguy at yahoo.com
Tue Feb 27 14:19:45 UTC 2018


On 2/27/18 7:20 AM, Timothee Cour wrote:
> this would be more bearable if there was a standard @trusted method to
> get array `.ptr`, eg:
> in `object.d` (so that it's indeed standard)
> 
> ```
> @trusted @nogc pure nothrow
> auto pointer(T)(T a){
>    return a.ptr;
> }
> ```

That completely defeats the purpose of the restriction! Of course we 
aren't going to do that :)

This is the standard way (and it's on you to make sure you don't mess it 
up):

auto x = (() @trusted => a.ptr)();

> again, the deprecation message is misleading because `&a[0]` isn't
> equivalent to `a.ptr`

It isn't equivalent, but it is a @safe mechanism to do it. If you want 
to do unsafe things, then you need to use @trusted escapes, 
druntime/phobos is not going to help you there.

-Steve


More information about the Digitalmars-d mailing list