Skip to content

Instantly share code, notes, and snippets.

@run-dlang
Created October 30, 2023 08:46
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 run-dlang/628e87c414574ebec83160340a8bc19e to your computer and use it in GitHub Desktop.
Save run-dlang/628e87c414574ebec83160340a8bc19e to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
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