On Tuesday, 2 April 2019 at 07:47:29 UTC, Stefan Koch wrote:
On Tuesday, 2 April 2019 at 03:15:36 UTC, Alex wrote:
Is there any way to build an alias array at compile time that isn't too heavy in resources?
{...}

Hi Alex,

I agree that there should be a way to do that.

As soon as newCTFE is a releasable state, I'll work on that again :)

I'd be intereseted in your usecases, so I can asses the requirements better.

Thanks in advance!

- Stefan

I'm just trying to filter out certain types from a static foreach to use later that are not used immediately. I usually need such a way to build an sequence though.

static foreach(a; Seq)
{
   static if (is(a == S))
   {
   } else arr.Add(a);
}

The idea is that I can then do

static foreach(a; arr)
{

}

to get the remaining elements.

Sometimes it's just building up up a sequence in some order for some reason such as collecting types and making decisions between those types.

Also, sometimes I want to create a hierarchy like a tree but nodes are sequences.

These things are easy to do at RT but nearly impossible at CT. With CTFE they can sorta be done but usually one still needs some way to build a sequence.

I mean, one can easily do this by using different names as I said:

alias arr1 = AliasSeq!(T1);
alias arr2 = AliasSeq!(arr1, T2);
alias arrnp1 = AliasSeq!(arrn, Tn);

but it's difficult to know the final name(well, one can use a mixin) and it has problems with scoping on static if's. The only point of doing it is because we can't reassign to an alias.

alias arr = AliasSeq!Empty;
static foreach(Tk; S)
{{
    alias arr = AliasSeq!(arr, Tk);
}}

Then arr == S after the loop.

would be ideal.




Reply via email to