Sequence separation

Engine Machine via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 17 11:38:48 PDT 2016


On Wednesday, 17 August 2016 at 08:37:32 UTC, Lodovico Giaretta 
wrote:
> On Tuesday, 16 August 2016 at 23:18:28 UTC, Adam D. Ruppe wrote:
>> On Tuesday, 16 August 2016 at 19:17:27 UTC, Engine Machine 
>> wrote:
>>> alias x = AliasSeq!(a, b, AliasSeq!(c, d));
>>>
>>> results in a flat sequence. I would like to be able to keep 
>>> them separate so I can have sub sequences.
>>
>> wrap them in a struct.
>
> You mean something like:
>
> struct MySequence(Args...)
> {
>     enum length = Args.length;
>     alias args = Args;
> }
>
> alias x = MySequence!(a, b, MySequence!(c, d));
>
> static assert(x.length == 3)
> static assert(x.args[2].length == 2);

Thanks, basically works.

How can I test, though, if a argument uses a MySequence? I can't 
do if (Args[0] == MySequence) because MySequence is templated. 
While I could test for a length, that doesn't work because some 
types have a length. I could add another enum to MySequence, but 
again, not safe.

I could do some string tests, but that doesn't work.

in your exmaple,

if (x.args[2] == MySequence) ??

I simply need to differentiate between a parameter/arg being a 
MySequence and not.





More information about the Digitalmars-d-learn mailing list