Thread overview
Transform static immutable string array to tuple.
Feb 19, 2023
realhet
Feb 19, 2023
ag0aep6g
Feb 19, 2023
realhet
Feb 19, 2023
H. S. Teoh
February 19, 2023

Hello,

Is there a better way to transform a string array to a tuple or to an AliasSeq?

mixin(customSyntaxPrefixes.format!`tuple(%(%s,%))`)

I'd like to use this as variable length arguments passed to the startsWith() std function (as multiple needles).

February 19, 2023

On Sunday, 19 February 2023 at 11:08:34 UTC, realhet wrote:

>

Is there a better way to transform a string array to a tuple or to an AliasSeq?

mixin(customSyntaxPrefixes.format!`tuple(%(%s,%))`)

https://dlang.org/phobos/std_meta.html#aliasSeqOf

February 19, 2023
On Sun, Feb 19, 2023 at 11:08:34AM +0000, realhet via Digitalmars-d-learn wrote:
> Hello,
> 
> Is there a better way to transform a string array to a tuple or to an AliasSeq?
> 
> ```
> mixin(customSyntaxPrefixes.format!`tuple(%(%s,%))`)
> ```
> 
> I'd like to use this as variable length arguments passed to the
> startsWith() std function (as multiple needles).

In situations like this it's often better to define your dats as an AliasSeq to begin with, since it's easier to covert that to an array than the other way round.


T

-- 
I don't trust computers, I've spent too long programming to think that they can get anything right. -- James Miller
February 19, 2023

Awesome, Thank both of you!

    enum a = ["A", "B"];
    writeln(a);
    writeln(aliasSeqOf!a);
    writeln([aliasSeqOf!a]);