www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Index an AliasSeq with a run-time index

reply Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
How do I index an `AliasSeq` with an integer known at run-time?
Aug 14 2022
parent reply ag0aep6g <anonymous example.com> writes:
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
parent Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Sunday, 14 August 2022 at 10:41:20 UTC, ag0aep6g wrote:
 On 14.08.22 12:08, Per Nordlöw wrote:
 How do I index an `AliasSeq` with an integer known at run-time?
Thanks
Aug 14 2022