www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Transform static immutable string array to tuple.

reply realhet <real_het hotmail.com> writes:
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).
Feb 19 2023
next sibling parent reply ag0aep6g <anonymous example.com> writes:
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
Feb 19 2023
parent realhet <real_het hotmail.com> writes:
Awesome, Thank both of you!

```
     enum a = ["A", "B"];
     writeln(a);
     writeln(aliasSeqOf!a);
     writeln([aliasSeqOf!a]);
```
Feb 19 2023
prev sibling parent "H. S. Teoh" <hsteoh qfbox.info> writes:
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
Feb 19 2023