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

Timothee Cour thelastmammoth at gmail.com
Tue Feb 27 20:37:47 UTC 2018


> Hm... borrowing from Timothee's suggestion:
> This would be fine and @safe, but may not be useful for all purposes. However, it would fix your issue.


how about this: https://github.com/dlang/phobos/pull/6231

On Tue, Feb 27, 2018 at 12:09 PM, Steven Schveighoffer via
Digitalmars-d <digitalmars-d at puremagic.com> wrote:
> On 2/27/18 3:00 PM, Steven Schveighoffer wrote:
>>
>> On 2/27/18 12:32 PM, Atila Neves wrote:
>>
>>> There's a common case where it's not equivalent - when the pointer is
>>> null. Imagine I have a C function I want to call:
>>>
>>> extern(C) void fun(int* things);
>>>
>>> Imagine also that it's ok to call with null. Well, now I can't use a
>>> slice to call this and have it be 1) @safe and 2) not throw RangeError. I
>>> ran into this the other way.
>>
>>
>> fun(x.length ? &x[0] : null);
>
>
> Hm... borrowing from Timothee's suggestion:
>
> @trusted @nogc pure nothrow
> T* pointer(T)(T[] a){
>    return a.length > 0 ? a.ptr : null;
> }
>
> This would be fine and @safe, but may not be useful for all purposes.
> However, it would fix your issue.
>
> -Steve


More information about the Digitalmars-d mailing list