How to print more when a statement fails?

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];
}

Today this statement failed, and I wanted to see the actual values rowand col. Unfortunately, it assertdoesn't look like writelnor writefln, so I can't do something like:

assert(col + row * Col < Row * Col, "index out of bounds. row: %d  col: %d", row, col);

I even tried this:

assert(col + row * Col < Row * Col, "index out of bounds" ~ to!string(row)~ " " ~ to!string(col));

But I canโ€™t name to, because it opIndexis clean. I could temporarily remove purefrom opIndex, but this causes a long chain to undo, because other clean methods call opIndex. The inability to call toalso precludes the possibility of creating my own function to go to assert.

So what else can you try? I just want to print such values โ€‹โ€‹when the statement fails.

+5
source share
1

, pure, . , std.conv.to pure, , . pure, . const - dmd (2.059), pure , Object pure, const, @safe nothrow. , , std.conv.to pure . , , ( ). .

, ,

assert(col + row * col < row * col,
       format("index out of bounds. row: %d  col: %d", row, col));

, format pure, pure.

debug. , ,

debug
{
    assert(col + row * col < row * col,
           format("index out of bounds. row: %d  col: %d", row, col));
}

-debug, . , debug pure , -debug, format to.

+10

All Articles