@trusted assumptions about @safe code
Steven Schveighoffer
schveiguy at gmail.com
Wed May 27 16:27:32 UTC 2020
On 5/27/20 8:52 AM, Stefan Koch wrote:
> On Wednesday, 27 May 2020 at 12:48:46 UTC, Steven Schveighoffer wrote:
>> On 5/27/20 2:36 AM, ag0aep6g wrote:
>>>> [...]
> 's relying on is actually true:
>>> [...]
>>
>> I think this is not the way to view it. @safe code still should do
>> what it's supposed to do. It's not any harder *or any easier* to call
>> @safe code.
>>
>> [...]
>
>
>
> {
> const i = cast(ssize_t) indexof(x, E);
> if (i < 0 || i > x.dim)
> {
> // no luck.
> }
> else
> {
> index is in bounds so use it.
> }
> }
Again, I also think this is valid @trusted code:
const i = indexof(x, E);
if(i != -1){
// use it
}
or
if(i != x.length)
{
// use it
}
depending on the spec for that function.
I don't think it's 100% necessary to be defensive on all semantics
assuming they are not implemented properly.
People just aren't going to write what you wrote in the name of @safe.
They *could* write:
size_t i = indexof(x, E);
if(i < x.length) {
}
But most people aren't going to do that either.
-Steve
More information about the Digitalmars-d
mailing list