d结构用作多维数组的索引

阅读 60

2022-06-11

​​原文​​

import std.stdio;
import std.format;

struct indexedPair {
size_t x, y;
}

struct MyArray {
bool[3][3] elements;

ref opIndex(indexedPair i) {
return elements[i.y][i.x];
}
}

void main() {
auto arr = MyArray();
auto p = indexedPair(1, 1);

arr[p] = true;
writeln(arr);
}


精彩评论(0)

0 0 举报