Skip to content

Instantly share code, notes, and snippets.

@run-dlang
Created November 1, 2023 22:18
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/5fbbaf56bafd4786ff3a5bceb5233d79 to your computer and use it in GitHub Desktop.
Save run-dlang/5fbbaf56bafd4786ff3a5bceb5233d79 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
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