On Sunday, 17 August 2025 at 14:17:42 UTC, 0xEAB wrote:
On Sunday, 17 August 2025 at 14:15:37 UTC, 0xEAB wrote:
Unless you provide `-debug` as well, you should not get
identifier-less ones compiled in as well.
```
import std.stdio;
void main() {
writeln("foo");
debug writeln("bar");
debug(foobar) writeln("foobar");
}
```
As far as I can tell, `dmd -debug=foobar -run app.d` reliably
outputs across various compiler versions:
```
foo
foobar
```
Success!
```
dmd -debug=binarySearch -run source/app.d
```
```
searching 42 among [-100, 0, 1, 2, 7, 10, 42, 365, 1000]
searching 42 among [10, 42, 365, 1000]
must be in the first half
searching 42 among [10, 42]
Index: 1
```
```
import std.stdio;
void main() {
auto numbers = [-100, 0, 1, 2, 7, 10, 42, 365, 1000];
auto index = binarySearch(numbers, 42);
writeln("Index: ", index);
}
size_t binarySearch(const int[] values, int value) {
debug(binarySearch) writefln("searching %s among %s", value,
values);
if (values.length == 0) {
debug writefln("%s not found", value);
return size_t.max;
}
immutable midPoint = values.length / 2;
debug writefln("considering index %s", midPoint);
if (value == values[midPoint]) {
debug writefln("found %s at index %s", value, midPoint);
return midPoint;
} else if (value < values[midPoint]) {
debug(binarySearch) writefln("must be in the first half");
return binarySearch(values[0 .. midPoint], value);
} else {
debug writefln("must be in the second half");
return binarySearch(values[midPoint + 1 .. $], value);
}
}
```