Is there pending work on a dynamic variant for this?
Comment #3 by andrej.mitrovich — 2014-04-21T08:58:41Z
(In reply to Per Nordlöw from comment #2)
> Is there pending work on a dynamic variant for this?
Can you elaborate?
Comment #4 by per.nordlow — 2014-04-21T09:15:49Z
Elaboration from my previous post:
I'v been wanting to have a similar dynamic behaviour for
assert(EXPR)
where EXPR is of the form
x OP y
where OP typically is a logical comparison operator ==, !=, <, >, <=, >=.
For example if
assert(x == y)
fails it should in some useful way explain to the user why it failed.
For small structures (for example builtin scalar types) it could just print them.
For larger structures/ranges it would be more useful to print the first (index, value) of x and y where the assertion failed. This should probably apply recursively, for example
Exception: assert(x == y) failed for i:th element of j:th element of ... x being X and ... of y being Y
For large structures this may result in a significant increase in code generation (and compilation time) for all the to!string instantiations the needs to be made. Maybe a compiler flag is motivated in this case.
Comment #5 by andrej.mitrovich — 2014-04-21T09:20:11Z
(In reply to Per Nordlöw from comment #4)
> I've been wanting to have a similar dynamic behaviour
Ah you mean runtime. There is some related work on improving assert itself, although it doesn't go as far as you've talked about. See https://github.com/D-Programming-Language/dmd/pull/1426