Created
February 21, 2026 23:08
-
-
Save crazymonkyyy/806a9b701e1c9eb46c620bd6f35eac16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!opend test app | |
| import std; | |
| struct intutisive(alias Array,discrim...){ | |
| static Array array; alias array this; | |
| //this(){ | |
| // array~=typeof(array[0]); | |
| //} | |
| auto opIndex(I)(I i){ | |
| static struct handle{ | |
| I i; | |
| ref get()=>array[i]; alias get this; | |
| string toString()=>get.to!string; | |
| auto children(){ | |
| static struct kidhandle{ | |
| I i; | |
| ref front()=>array[i]; | |
| void popFront(){i=front.sib;} | |
| bool empty()=>i==0; | |
| //void opOpAssign(string op:"~")(handle a){//I dont think this works without a parent pointer | |
| // a.sib=front.sib; | |
| // front.sib=a.i; | |
| //} | |
| } | |
| return kidhandle(get.kid); | |
| } | |
| void addchild(handle a){ | |
| a.sib=get.kid; | |
| get.kid=cast(typeof(get.kid))a.i; | |
| } | |
| } | |
| return handle(i); | |
| } | |
| auto length()=>array.length-1; | |
| auto opSlice()=>iota(1,array.length).map!(i=>opIndex(i)); | |
| } | |
| struct data{ | |
| string name; | |
| ubyte kid; | |
| ubyte sib; | |
| } | |
| intutisive!(data[]) foo; | |
| unittest{ | |
| foo~=data(""); | |
| foo~=data("hi"); | |
| assert(foo[1].children.empty); | |
| foo~=data("bye"); | |
| foo[1].kid=2; | |
| assert(foo[1].children.front.name=="bye"); | |
| foo[].writeln; | |
| //--- | |
| foo~=data("cow"); | |
| foo~=data("moo"); | |
| foo[].filter!(a=>a.name=="cow").front.addchild( foo[].filter!(a=>a.name=="moo").front ); | |
| foo[].writeln; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment