another cool RTInfo trick - i want in runtime

Adam D. Ruppe destructionator at gmail.com
Thu Jan 16 11:13:41 PST 2014


On Thursday, 16 January 2014 at 18:44:54 UTC, Namespace wrote:
> I guess that could work pretty well for a C++ friend emulation 
> with UDA's! Were not you the one who wanted to show me an 
> example for that with using RTInfo?

I've played with rtinfo a lot before, but I don't remember doing 
C++ friend emulation...

> Offer your way the possibility to check automatically for null 
> references? With an UDA e.g. @safe_ref or @not_null

I think those would be better done with the type info, like 
NotNull!t.

What's cool about the RTInfo thing though is it is checked on 
everything, so it can check for the *absence* of a UDA as well as 
for the presence.

You might say something must not have any nullable references 
unless specially marked. The rtinfo checker can confirm that: 
loop over all members, if it is potentially nullable and isn't 
marked with either NotNull or 
@i_know_this_is_nullable_and_that_is_ok, it can throw an error.

It is possible to do that kind of thing with static assert on the 
module level too.... sort of. See, the module level one for one 
can be forgotten and it can't access nested things in functions:

void foo() {
   struct InnerStruct {}
}

// can't see foo.InnerStuct here!
static assert(ModulePassesCheck!(mixin("this_module")));


But RTInfo *does* see InnerStruct, and you don't have to remember 
to add the check to your module too.


More information about the Digitalmars-d mailing list