Encapsulating trust

Dmitry Olshansky via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 1 00:13:43 PDT 2014


01-Sep-2014 00:36, monarch_dodra пишет:
> On Sunday, 31 August 2014 at 13:47:42 UTC, Dmitry Olshansky wrote:
>> What do you guys think?
>
> I'd say add "trusted" to those function names:
> "trustedCall"
> "trustedAddrOf"
>

Would we ever use our module system? I agree though that being easily 
grep-able is useful for these functions.

assumeSafe?

> Because:
> - "call" could mean a lot of things. It's not imidiatly obvious that it
> is meant for being trusted.
> - "addrOf" is *also* used as an alternative for "&", especially in
> generic code, when you need the address of an attribute, as that
> attribute could actually be a property function. EG:
> auto p = addrOf(r.front);
> Nothing here implies trust.

Local import of 'trusted' right there might imply trust. Selective, 
preferably static.

>
> Also, implementation wise, wouldn't it be possible to instead make
> `call` a template aliases itself away to `fun`, but with different
> attributes? The `auto fun(Args)(auto ref Args args)` tube approach has
> the disadvantages that it:
> - prevents return by ref

auto ref return FTW

> - fails perfect forwarding of lvalues into rvalues.

?

void inc(ref int a)
{
     a += 1;
}
     int b;
     call!inc(b);
     assert(b == 1);

Works fine.

-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list