Skip to content

Instantly share code, notes, and snippets.

@thedeemon
Last active November 22, 2020 19:54
Show Gist options
  • Save thedeemon/f1bb8c5d5c76f1b232dbe050b274407d to your computer and use it in GitHub Desktop.
Save thedeemon/f1bb8c5d5c76f1b232dbe050b274407d to your computer and use it in GitHub Desktop.
A test of @LiVe in D
// dmd -preview=dip1021 liev.d
import std.stdio;
struct S { string name; }
@live void use(scope const S* p) { // ok
writeln(p.name);
}
void release(S *p) { } // consumes the ownership
// how do I make this work?
@live auto longer(scope const S* a, scope const S* b) {
if (a.name.length > b.name.length)
return a;
else
return b;
}
@live void foo()
{
auto a = new S("aaa");
auto b = new S("bb");
auto c = longer(a,b); // if you comment out this line, it compiles
release(a);
release(b);
}
void main() {
writeln("hi!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment