Thread overview | |||||
---|---|---|---|---|---|
|
December 11, 2010 Unqual for @safe @system and @trusted | ||||
---|---|---|---|---|
| ||||
Is there something like Unqual that can remove the safety attributes from a type? Unqual doesn't work: ----------------------------------------------------------------------------------- class handler { @safe void opCall(int i) {} } static assert(is(Unqual!(typeof(&(handler.init.opCall))) == void delegate(int))); ----------------------------------------------------------------------------------- event.d(554): Error: static assert (is(void delegate(int i) @safe == void delegate(int b))) is false -- Johannes Pfau |
December 11, 2010 Re: Unqual for @safe @system and @trusted | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johannes Pfau | Johannes Pfau:
> Is there something like Unqual that can remove the safety attributes from a type?
In such cases we have to ask what's your use case/purpose. Isn't @trusted enough?
Bye,
bearophile
|
December 12, 2010 Re: Unqual for @safe @system and @trusted | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | Am 11.12.2010, 19:33 Uhr, schrieb bearophile <bearophileHUGS@lycos.com>: > Johannes Pfau: > >> Is there something like Unqual that can remove the safety attributes from >> a type? > > In such cases we have to ask what's your use case/purpose. Isn't @trusted enough? > > Bye, > bearophile Well, for my signal implementation (Latest code: http://ideone.com/SM11K ) I have templates which accept functions, delegates and callable objects. I used something like "static if(is(T == void delegate(int)))" to check if: 1. T is a delegate 2. it returns void 3. it takes one int parameter In this case I'm only interested in these three points, I don't care if T is @safe @trusted or @system, but the above check fails if T is @safe. I found a solution though, I now do these checks with functions from std.traits: ReturnType!(T) for the return type, is(typeof(T.init(Init!(Types)))) for parameters and is(T == delegate). Seems to work fine now. -- Johannes Pfau |
Copyright © 1999-2021 by the D Language Foundation