On Thursday, 16 January 2014 at 19:13:42 UTC, Adam D. Ruppe wrote:
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.

All right, it wasn't you, it was Andrej Mitrovic on my thread http://forum.dlang.org/thread/pdshwedjqgquoibxh...@forum.dlang.org#post-mailman.1977.1381065059.1719.digitalmars-d-learn:40puremagic.com

The problem on a library NotNull struct is: nobody will use it, because it requires NotNull on both sides, by the caller and by the callee:

----
class A { }

void safe_foo(NotNull!A na) { }

void main() {
    NotNull!A na = NotNull!A(new A());
    safe_foo(na);
}
----

Which is a lot more effor than:

----
class A { }

void safe_foo(@safe_ref A na) { }

void main() {
    A a = new A();
    safe_foo(a);
}
----

because it moves the check to the callee.

Reply via email to