Skip to content

Instantly share code, notes, and snippets.

@run-dlang
Created September 29, 2023 18:01
Show Gist options
  • Save run-dlang/d1a59c4bd234f33dddb06a5582bae8f1 to your computer and use it in GitHub Desktop.
Save run-dlang/d1a59c4bd234f33dddb06a5582bae8f1 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
import std.stdio, std.format;
import std.algorithm;
struct BoolMatrix(int n)
{
 bool[n][n] elements;
 enum err1 = n.format!"Point, %s'e denk veya fazla olamaz!";
 ref opCall(Point i)
 in(i.y <n && i.x <n, err1)
   => elements[i.y][i.x];
 alias toSink = void delegate(in char[]);
 void toString(scope toSink sink) const
{
sink.formattedWrite!"%-(%-(%s %)\n%)"(
elements[].map!(
(ref row) =>
row[].map!(
           col => col ? '1' : '0'
)
      )
   );
}
}
struct Point { int x, y; }
void main() {
 BoolMatrix!5 arr;
 auto p = Point(2, 2);
 arr(p) = true;
 arr.writeln;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment