Sequence separation
Engine Machine via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Aug 17 12:38:22 PDT 2016
On Wednesday, 17 August 2016 at 19:15:48 UTC, ag0aep6g wrote:
> On 08/17/2016 08:38 PM, Engine Machine wrote:
>> [...]
> [...]
>> [...]
>
> With MySequence being a type, you can do this:
>
> ----
> static if (is(x.args[2] == MySequence!Args, Args ...))
> {
> ...
> }
> ----
>
It works! Nifty that you can do that with is.
> Aside from this check, there is probably not much use for
> MySequence being a type. So I'm be tempted to find a way to do
> the check with a raw template MySequence.
>
> As you said, another enum alone doesn't cut it. The faker can
> just add the same enum.
>
> But a private enum of a private type might do it:
>
> ----
> template MySequence(Args ...)
> {
> /* ... length and args ... */
> private enum id = Id();
> }
>
> private struct Id {}
>
> enum isMySequence(alias seq) = is(typeof(seq.id) == Id);
> ----
>
> Other modules can't use the Id type directly, because it's
> private. And they can't use typeof(MySequence!foo.id), because
> the id member is private, too.
>
> However, I wouldn't be surprised if this can be circumvented
> too.
Well, the is does work and that probably is the best solution. I
don't mind the extra type at this point. Of course, a library
solution for this type of stuff would be nice. I'd rather not
have to even use a type but rather use arrays:
[a,b,[c,d]].
More information about the Digitalmars-d-learn
mailing list