Created
October 30, 2023 08:46
-
-
Save run-dlang/628e87c414574ebec83160340a8bc19e to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio; | |
import std.datetime; | |
import std.stdint; | |
import std.conv; | |
class Writer | |
{ | |
this(void delegate() del) | |
{ | |
_del = del; | |
} | |
auto apply() | |
{ | |
_del(); | |
} | |
void delegate() _del; | |
} | |
int main() | |
{ | |
int[] l = [1, 2, 3, 4]; | |
void doStuff() {writeln(l);} | |
auto w = new Writer(&doStuff); | |
w.apply; | |
l ~= [3, 4]; | |
w.apply; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment