Ive been trying to extend `tg ct counter` (im renaming the pattern to `ct value`, because it appears to work for everything and is very generic) into some sort of list, hopefully a range. I tried to do it with a linked list like structure, but I think its a dead end because the ct gc has opinionated typed casting check and its possible that ct pointers that I trick pass the compiler just would stop working.

I could update my original `appendable alias seq` with `value aliases` but I remember thinking the time complexity of that was n^2 read and writes; Im a little fuzzy on the details on how I came to that conclusion; but its not great and I never used it for a reason. While I did end up using my ct counter(original, much worse then tg's) that I discovered while making it.

Current dead end:

```d
--- meta.d
enum counter=cast(immutable(void)*)[0].ptr;
auto count()=>(*(cast(int*)counter))++;
auto getcount()=>(*(cast(int*)counter));

template innate(T,int i){
    T innate;
}
template ctval(T,int i){
    enum point=cast(immutable(void)*)[T.init].ptr;
    auto get()=>(*(cast(T*)counter));
    auto set(T t){(*(cast(T*)counter))=t; return true;}
    auto apply(alias F)(){
    enum _=set(F(get()));
        return true;
    }
}
unittest{
    //alias A=ctval!int;
}
struct linked(T){
    T val;
    int i;
    linked!T* next;
    auto front()=>val;
    void popFront(){this=next;}
    bool empty()=>i<getcount;
}
template add(alias t){
    alias T=typeof(t);
    enum curcount=getcount;
    alias me=ctval!(linked!T,curcount);
    enum meset=me.apply!((p){p.val=t;p.i=curcount;return p;});
    enum countup=count;
    alias next=ctval!(linked!T,countup);
    enum nextp=cast(const linked!T*)(next.point);
enum nextset=me.apply!((p){p.next=cast(linked!T*)nextp;return p;});
}
--- foo.d
import std;
import meta;
alias a=add!1;
//alias b=add!2;
unittest{
    ctval(linked!T,0).writeln;
}
```

(eventually Id add a bar.d and would want it to spookly effect foo's unit test)

I see two paths forward, learn headconst shit trying to dodge the compiler safety mechinism and hope that ct values of pointers work(I expect they dont). Update my appendable aliasseq from my old ct counter pattern to tg counter pattern and then alias vals(which are kinda bad anyway)

Can someone think of a different thoery?

---
foot notes:

my original ct counter used `mixin("__LINE__")` and a compiler flag creating 100's of lines of code in magical mixin land, creating what must be awful over head and a nonconst bigO, I believe tg ct counter has maybe a few hundred bytes of overhead and is const reads and writes

Alias vals for anyone who hasnt figured out this work around; enum reassignment should still happen, but if you eat the ugly syntax its possible today.

```d
alias seq(T...)=T;
template val(alias V){enum val=V;}
template foo(T...){
    alias foo=seq!();
    static foreach(I,A;T){
        foo=seq!(foo,val!(I));
}}
unittest{
    import std;
    foo!(int,int,int).stringof.writeln;
}
```

Reply via email to