Re: Temporary @trusted scope

2018-12-19 Thread rikki cattermole via Digitalmars-d-learn
On 20/12/2018 5:02 AM, Jonathan M Davis wrote: On Wednesday, December 19, 2018 1:19:42 AM MST rikki cattermole via Digitalmars-d-learn wrote: On 19/12/2018 7:11 PM, Jonathan M Davis wrote: Really? I would have thought that that would be a pretty obvious optimization (especially if inlining is

Re: Temporary @trusted scope

2018-12-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, December 19, 2018 1:19:42 AM MST rikki cattermole via Digitalmars-d-learn wrote: > On 19/12/2018 7:11 PM, Jonathan M Davis wrote: > > Really? I would have thought that that would be a pretty obvious > > optimization (especially if inlining is enabled). > > Assembly doesn't lie. I'm

Re: Temporary @trusted scope

2018-12-19 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 13:52:29 UTC, Steven Schveighoffer wrote: On 12/18/18 6:29 AM, Simen Kjærås wrote: @safe unittest {     unsafe!({     fun(2);     });     unsafe!fun(2); } Wow, I really like this. The only real problem is that one generally searches for @trusted when

Re: Temporary @trusted scope

2018-12-19 Thread rikki cattermole via Digitalmars-d-learn
On 19/12/2018 7:11 PM, Jonathan M Davis wrote: Really? I would have thought that that would be a pretty obvious optimization (especially if inlining is enabled). Assembly doesn't lie.

Re: Temporary @trusted scope

2018-12-19 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 19 December 2018 at 06:11:48 UTC, Jonathan M Davis wrote: Really? I would have thought that that would be a pretty obvious optimization (especially if inlining is enabled). I suppose that it doesn't entirely surprise me if dmd does a poor job of it, but I would have expected ldc

Re: Temporary @trusted scope

2018-12-19 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 12:42:12 UTC, rikki cattermole wrote: Yes except for ldc with -O3. ldc with -O2 generates the same code.

Re: Temporary @trusted scope

2018-12-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, December 18, 2018 5:42:12 AM MST rikki cattermole via Digitalmars-d-learn wrote: > On 19/12/2018 1:34 AM, Per Nordlöw wrote: > > On Tuesday, 18 December 2018 at 10:42:51 UTC, Jonathan M Davis wrote: > >> Unfortunately, D does not currently have a way to do that. Only > >> functions

Re: Temporary @trusted scope

2018-12-18 Thread aliak via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 13:52:29 UTC, Steven Schveighoffer wrote: On 12/18/18 6:29 AM, Simen Kjærås wrote: On Tuesday, 18 December 2018 at 10:14:50 UTC, Per Nordlöw wrote: What's the preferred way of creating a temporary @trusted scope without writing a separate  function? Jonathan's

Re: Temporary @trusted scope

2018-12-18 Thread Steven Schveighoffer via Digitalmars-d-learn
@trusted scope without writing a separate  function? Jonathan's idea might also be encapsulated in a function, just like assumeUnique in Phobos: import std.stdio; template unsafe(alias fn) {     @trusted auto unsafe(T...)(T args) {     return fn(args);     } } @system void fun(int n

Re: Temporary @trusted scope

2018-12-18 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 18, 2018 at 08:52:29AM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: > On 12/18/18 6:29 AM, Simen Kjærås wrote: > > On Tuesday, 18 December 2018 at 10:14:50 UTC, Per Nordlöw wrote: > > > What's the preferred way of creating a temporary @trusted scope >

Re: Temporary @trusted scope

2018-12-18 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 13:52:29 UTC, Steven Schveighoffer wrote: template unsafe(alias fn) {     @trusted auto unsafe(T...)(T args) {     return fn(args);     } } Very nice! What about proposing this for inclusion into `std.typecons` or `std.meta`?

Re: Temporary @trusted scope

2018-12-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/18/18 6:29 AM, Simen Kjærås wrote: On Tuesday, 18 December 2018 at 10:14:50 UTC, Per Nordlöw wrote: What's the preferred way of creating a temporary @trusted scope without writing a separate  function? Jonathan's idea might also be encapsulated in a function, just like assumeUnique

Re: Temporary @trusted scope

2018-12-18 Thread rikki cattermole via Digitalmars-d-learn
On 19/12/2018 1:34 AM, Per Nordlöw wrote: On Tuesday, 18 December 2018 at 10:42:51 UTC, Jonathan M Davis wrote: Unfortunately, D does not currently have a way to do that. Only functions can be marked with @trusted. However, the typical approach to this problem is to use a lambda, which is more

Re: Temporary @trusted scope

2018-12-18 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 10:42:51 UTC, Jonathan M Davis wrote: Unfortunately, D does not currently have a way to do that. Only functions can be marked with @trusted. However, the typical approach to this problem is to use a lambda, which is more or less syntactically the same except

Re: Temporary @trusted scope

2018-12-18 Thread Simen Kjærås via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 10:14:50 UTC, Per Nordlöw wrote: What's the preferred way of creating a temporary @trusted scope without writing a separate function? Jonathan's idea might also be encapsulated in a function, just like assumeUnique in Phobos: import std.stdio; template

Re: Temporary @trusted scope

2018-12-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, December 18, 2018 3:14:50 AM MST Per Nordlöw via Digitalmars-d- learn wrote: > What's the preferred way of creating a temporary @trusted scope > without writing a separate function? > > Similar to Rust's > > unsafe { /* unsafe stuff here */ } Unfortunately, D does

Temporary @trusted scope

2018-12-18 Thread Per Nordlöw via Digitalmars-d-learn
What's the preferred way of creating a temporary @trusted scope without writing a separate function? Similar to Rust's unsafe { /* unsafe stuff here */ }