Created
July 19, 2023 06:54
-
-
Save run-dlang/491bf93c27fd9804098df2068da9ac73 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
This file contains 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; | |
alias section = void function(ulong s); | |
void bar(ulong s) { | |
writefln("bar(%d)",s); | |
return S(&bar)(s+1); | |
} | |
void baz(ulong s) { | |
writefln("baz(%d)",s); | |
} | |
void quux(ulong s) { | |
writefln("quux(%d)",s); | |
} | |
section S(section origin) { | |
if (origin is &bar) return &baz; | |
return null; | |
} | |
void main() | |
{ | |
writeln("Hello D"); | |
foo(iwrite!int, 123); | |
int x = 1; | |
foo((out int v){writefln("v=%s",v); v=234;},x); | |
foo(iwrite!int, x); | |
foo((ref int v){writefln("v=%s",v); v=345;},x); | |
foo(iwrite!int, x); | |
bar(1); | |
foreach(i; 0..2) writefln("%d",i); | |
} | |
void foo(T)(void function(in T v) f,const T v) { | |
//writefln("in v=%s",v); | |
f(v); } | |
void foo(T)(void function(out T v) f, ref T v) { | |
//writefln("out v=%s",v); | |
f(v); } | |
void foo(T)(void function(ref T v) f, ref T v) { | |
//writefln("mod v=%s",v); | |
f(v); } | |
auto iwrite(T)() { return (in T v) { | |
writefln("%s",v); | |
};} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment