secret
Created

NonNull struct test result

  • Download Gist
main.d
D
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
import NonNull, std.stdio;
 
// NonNull struct is located here:
// http://forum.dlang.org/thread/wspawctazpndhvdiouhz@forum.dlang.org
 
class Foo {
void stuff() {
writeln("Hi");
}
mixin TRef!(typeof(this));
}
 
void refThing(Ref!Foo f) {
f.stuff();
}
 
void thing(Foo f) {
f.stuff();
}
 
void main() {
Ref!Foo myRefFoo = new Foo;
Foo myFoo = new Foo;
//myFoo.thing(); // works if mixin TRef!(typeof(this)) is commented above
//myRefFoo.refThing();
// if mixin commented-> Error: function expected before (), not refThing(myRefFoo) of type void
// otherwise-> Error: forward reference to inferred return type of function call this._obj.getRef("C:\\D\\dmd2\\windows\\bin\\..\\..\\src\\phobos\\std\\typecons.d",2847u).opDispatch()
// Error: template instance NonNull.Ref!(Foo).Ref.Proxy!(_obj).opDispatch!("refThing").opDispatch!(Ref!(Foo)) error instantiating
//myRefFoo.thing();
// if mixin commented-> Error: function main.thing (Foo f) is not callable using argument types (Ref!(Foo))
// Error: cannot implicitly convert expression (myRefFoo) of type Ref!(Foo) to main.Foo
// otherwise -> same as myRefFoo.refThing()
//myFoo.refThing();
// same as myRefFoo.thing();
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.