@trusted delegates all over std.array

Jonathan M Davis jmdavisProg at gmx.com
Sun Feb 2 14:22:22 PST 2014


On Sunday, February 02, 2014 22:46:02 Andrej Mitrovic wrote:
> On 2/2/14, Jesse Phillips <Jesse.K.Phillips+D at gmail.com> wrote:
> > Pretty sure @trusted only affect the use of @safe and never makes
> > CTFE work.
> 
> This is what I remember, it has a huge diff and has lots of these
> trusted lambdas in it:
> https://github.com/D-Programming-Language/phobos/pull/1337/files

I think that the fact that the pull is labeled as "potentially @safe & pure 
formatting" doesn't have anything to do with the @trusted lambda stuff that's 
part of it. I believe that the @trusted lambda is a trick that Kenj came up 
with to be able to mark an expression as @trusted rather than being forced to 
mark the whole function as @trusted or create a separate wrapper function to 
be able to mark part of it as @trusted. Rather, he creates a wrapper function 
in place and calls it.

We'd probably be better off figuring out how to add the ability to mark pieces 
of code as @trusted to the language rather than using this trick, since it's a 
bit clunky and probably incurs unnecessary overhead (though maybe Kenji added 
stuff to the compiler to optimize away the overhead of the lambda, or we're 
lucky and it already did). But in the meantime at least, it is a neat trick, 
since it allows us to restrict what code gets marked as @trusted within a 
function.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list