digitalmars.D.learn - Index a parameter tuple with a run-time index
- =?UTF-8?B?Tm9yZGzDtnc=?= (1/1) Jan 15 2016 How do I index a function parameter tuple with a run-time index?
- anonymous (22/23) Jan 15 2016 With a switch and a static foreach:
- Meta (3/27) Jan 15 2016 And of course I'm proven wrong as soon as I post :) Sometimes I
- Justin Whear (2/4) Jan 15 2016 Username doesn't check out, :(
- Meta (2/6) Jan 15 2016 Huh?
- Meta (6/7) Jan 15 2016 I believe it's impossible because a parameter tuple is not a
How do I index a function parameter tuple with a run-time index?
Jan 15 2016
On 15.01.2016 21:42, Nordlöw wrote:How do I index a function parameter tuple with a run-time index?With a switch and a static foreach: ---- void f(A...)(size_t i, A a) { import std.stdio: writeln; switch_: switch (i) { foreach (iT, T; A) { case iT: writeln(T.stringof); break switch_; } default: writeln("??"); break; } } void main() { f(0, "foo", 42); /* string */ f(1, "foo", 42); /* int */ f(2, "foo", 42); /* ?? */ } ----
Jan 15 2016
On Friday, 15 January 2016 at 20:48:39 UTC, anonymous wrote:On 15.01.2016 21:42, Nordlöw wrote:And of course I'm proven wrong as soon as I post :) Sometimes I forget how powerful D's code generation abilities are.How do I index a function parameter tuple with a run-time index?With a switch and a static foreach: ---- void f(A...)(size_t i, A a) { import std.stdio: writeln; switch_: switch (i) { foreach (iT, T; A) { case iT: writeln(T.stringof); break switch_; } default: writeln("??"); break; } } void main() { f(0, "foo", 42); /* string */ f(1, "foo", 42); /* int */ f(2, "foo", 42); /* ?? */ } ----
Jan 15 2016
On Fri, 15 Jan 2016 20:52:46 +0000, Meta wrote:And of course I'm proven wrong as soon as I post :) Sometimes I forget how powerful D's code generation abilities are.Username doesn't check out, :(
Jan 15 2016
On Friday, 15 January 2016 at 21:47:21 UTC, Justin Whear wrote:On Fri, 15 Jan 2016 20:52:46 +0000, Meta wrote:Huh?And of course I'm proven wrong as soon as I post :) Sometimes I forget how powerful D's code generation abilities are.Username doesn't check out, :(
Jan 15 2016
On Friday, 15 January 2016 at 20:42:47 UTC, Nordlöw wrote:How do I index a function parameter tuple with a run-time index?I believe it's impossible because a parameter tuple is not a runtime entity. If it was an expression tuple (a compile-time tuple of only values, no types or symbols) and all of the values had a common base type, you could put it in an array and index that.
Jan 15 2016