@trusted delegates all over std.array

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Sun Feb 2 12:10:05 PST 2014


On Sunday, 2 February 2014 at 17:47:21 UTC, Andrej Mitrovic wrote:
> On Sunday, 2 February 2014 at 17:40:47 UTC, TheFlyingFiddle 
> wrote:
>> Why is std.array litered with @trusted delegates?
>
> IIRC these were added in the last few releases to make code 
> CTFE-able or to allow pure code to call such functions. A lot 
> of array/string-processing code wasn't usable from CTFE/pure, 
> this was one workaround to the problem.

Pretty sure @trusted only affect the use of @safe and never makes 
CTFE work.

TheFlyingFiddle, the question is about this chunk of code:

     _data.arr = return _data.arr.ptr[0 .. 0];

Does this code run the risk of corrupting memory? The purpose of 
@trusted is to allow code which has been reviewed to be safe to 
be used in @safe code. It can do everything @system code can, but 
should be reserved for code that doesn't rely on the caller to 
provide proper data.

Since the compiler can't validate @system code to be safe, it 
relies on a human to tell it what is safe, this is where @trusted 
comes in.


More information about the Digitalmars-d-learn mailing list