June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,12 @@
interface Camera {
// A virtual function.
Image takePhoto();
// A non-virtual function.
final Image[] takeSeveralPhotos(int count) {
auto result = new Image[count];
foreach (ref img; result) {
img = takePhoto();
}
}
}

View file

@ -0,0 +1,38 @@
class A {
string foo() {
return "I am an A.";
}
}
class B {
string foo() {
return "I am a B.";
}
}
class C : A {
string className = "C";
override string foo() {
return "I am a "~className~", and thus an A.";
}
@property
BWrapper asB() {
return new BWrapper();
}
alias asB this;
class BWrapper : B {
override string foo() {
return "I am a "~className~", disguised as a B.";
}
}
}
unittest {
import std.stdio : writeln;
auto c = new C();
A a = c;
B b = c;
writeln(a.foo());
writeln(b.foo());
}

View file

@ -0,0 +1,19 @@
template registerable() {
void register() { /* implementation */ }
}
string makeFunction(string s) {
return `string `~s~`(){ return "`~s~`";}`;
}
class Foo {
mixin registerable!();
mixin(makeFunction("myFunction"));
}
unittest {
import std.stdio : writeln;
Foo foo = new Foo;
foo.register();
writeln(foo.myFunction());
}