Created
September 29, 2023 18:01
-
-
Save run-dlang/d1a59c4bd234f33dddb06a5582bae8f1 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
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
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