On Wednesday, 10 September 2025 at 20:23:28 UTC, monkyyy wrote:
I asked
does a preexisting nd array iterator exist?

got links to mir, docs I can barely read (srsly math language is anticomprehension)

ndslice allocates, so, hottake misnamed. A slice is a reference to an array, a dynmaic array is a gc allocated array https://opendlang.org/library/mir.ndslice.allocation.slice.4.html#Slice

Found `field`, says its a something defined by an opIndex, better, but no nd

`fieldnd.d`or something exists but it defines 2 types of nd fields and not a generic mapping, idk

`FieldIterator` exists but its opSlice only takes 2 arguments so I think I can rule it out as nd

etc.

So I dont think it exists in this tangled mess? Maybe, idk? I think in its naming scheme it would be called an ndfield

Will need to gentricify this, but this seems promising

```d
import std;
struct Tuple(T...){
        enum istuple=true;
        T expand; alias expand this;
}
auto tuple(T...)(T args){
        return Tuple!T(args);
}
unittest{
        auto foo=tuple(1,"hi");
        assert(foo[0]==1);
        assert(foo[1]=="hi");
        auto bar=tuple();
}
enum istuple(T)=is(typeof(T.istuple));
unittest{
        assert(istuple!(typeof(tuple(1,2)))==true);
        assert(istuple!int==false);
}
auto iterate(T,S)(T t,S s){
        struct foreach_{
        int opApply(int delegate(int,int) dg){
                int result;
                static foreach(TI;0..t.length){
                foreach(x;t[TI]){
                        static foreach(SI;0..s.length){
                        foreach(y;s[SI]){
                                result=dg(x,y);
                                if(result>2){return result;}
                                if(result==1){break;}
                        }}
                }}
                return result;
        }}
        return foreach_();
}
unittest{
        loop:foreach(x,y;iterate(tuple(iota(0,3),iota(6,9)),tuple(iota(4,6)))){
                writeln(x,',',y);
                if(x==6){break;}
                if(x==7){break loop;}
}}
```

Reply via email to