digitalmars.D.learn - Index an AliasSeq with a run-time index
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (1/1) Aug 14 2022 How do I index an `AliasSeq` with an integer known at run-time?
- ag0aep6g (18/19) Aug 14 2022 With a `switch` that has a `case` for every possible index:
- Per =?UTF-8?B?Tm9yZGzDtnc=?= (2/4) Aug 14 2022 Thanks
How do I index an `AliasSeq` with an integer known at run-time?
Aug 14 2022
On 14.08.22 12:08, Per Nordlöw wrote:How do I index an `AliasSeq` with an integer known at run-time?With a `switch` that has a `case` for every possible index: ---- import std.meta: AliasSeq; alias seq = AliasSeq!("foo", "bar", "baz"); string f(size_t rti) { sw: switch (rti) { static foreach (cti; 0 .. seq.length) { case cti: return seq[cti]; break sw; } default: break sw; } return ""; } ----
Aug 14 2022
On Sunday, 14 August 2022 at 10:41:20 UTC, ag0aep6g wrote:On 14.08.22 12:08, Per Nordlöw wrote:ThanksHow do I index an `AliasSeq` with an integer known at run-time?
Aug 14 2022