Skip to content

Instantly share code, notes, and snippets.

@Zshazz

Zshazz/main.d Secret

Created May 7, 2012 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zshazz/6198938b9c6d40a53ca1 to your computer and use it in GitHub Desktop.
Save Zshazz/6198938b9c6d40a53ca1 to your computer and use it in GitHub Desktop.
NonNull struct test result
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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment