Created
April 22, 2014 07:48
-
-
Save pontifechs/11169069 to your computer and use it in GitHub Desktop.
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
module tinker; | |
import std.stdio; | |
class A | |
{ | |
int foo; | |
float bar; | |
} | |
class B | |
{ | |
int baz; | |
float qux; | |
} | |
class DynamicTuple(T...) | |
{ | |
T tuple; | |
string[] names; | |
this() | |
{ | |
auto names = ["one", "two", "three"]; | |
foreach (int i, name; names) | |
{ | |
this.names ~= name; | |
} | |
} | |
auto notopDispatch(string s)() @property | |
{ | |
foreach (i, elem; tuple) | |
{ | |
if (names[i] == s) | |
{ | |
return elem; | |
} | |
} | |
assert(false); | |
} | |
} | |
void main() | |
{ | |
auto s = new DynamicTuple!(A,B)(); | |
s.notopDispatch!("one")(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment