[email protected] import std.stdio; import std.format; struct indexedPair { size t x, y; } struct MyArray { bool 3 3 elements; ...">

当前位置:网站首页>D structure as index of multidimensional array

D structure as index of multidimensional array

2022-06-11 04:12:00 fqbqrr

original text

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);
}
原网站

版权声明
本文为[fqbqrr]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110354592847.html