Real opIndex(size_t row, size_t col = 0) const pure nothrow {
assert(col + row * Col < Row * Col, "index out of bounds.");
return _data[col + row * Col];
}
今天这个断言失败了,我想看看row
和col
的实际值。偏偏assert
不像writeln
或writefln
,所以我不能做这样的事情:断言失败时如何打印更多内容?
assert(col + row * Col < Row * Col, "index out of bounds. row: %d col: %d", row, col);
我甚至试过这样:
assert(col + row * Col < Row * Col, "index out of bounds" ~ to!string(row)~ " " ~ to!string(col));
但我不能叫to
因为opIndex
是纯。我可以暂时从opIndex
中删除pure
,但是这会触发长链撤消,因为其他纯粹的方法正在呼叫opIndex
。不能拨打to
也消除了创建我自己的功能传递到assert
的可能性。
那么,还有什么可以尝试?我只是想在断言失败时打印这些值。