www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Unqual for safe system and trusted

reply "Johannes Pfau" <spam example.com> writes:
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
Dec 11 2010
parent reply bearophile <bearophileHUGS lycos.com> writes:
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
Dec 11 2010
parent "Johannes Pfau" <spam example.com> writes:
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
Dec 12 2010