Created
November 1, 2023 22:18
-
-
Save run-dlang/5fbbaf56bafd4786ff3a5bceb5233d79 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; | |
void main() | |
{ | |
string[string] aa; | |
string x = "xxx"; | |
aa["name"] = "Arthur"; | |
aa["quest"] = "seek the Holy Grail"; | |
aa["favoriteColor"] = "blue"; | |
with (aa.keysAsVars) | |
.writefln!"My name is %s, I %s, and my favorite color is %s."( | |
name, quest, x); | |
} | |
struct KeysAsVars(K, V) | |
{ | |
V[K] aa; | |
V opDispatch(string key)() => aa[key]; | |
} | |
KeysAsVars!(K, V) keysAsVars(K, V)(V[K] aa) | |
{ | |
return typeof(return)(aa); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment