__traits(compiles, ...) with syntax errors
Paul Backus
snarwin at gmail.com
Mon Jan 14 21:57:28 UTC 2019
On Monday, 14 January 2019 at 21:47:40 UTC, Steven Schveighoffer
wrote:
> How many times have you written something like:
>
> void foo(T)(T t) if (__traits(compiles, t.bar())) // or
> is(typeof(t.bar()))
> {
> t.bar();
> }
>
> And somehow, somewhere, this isn't called? Then you remove the
> constraint, and find that there's a syntax error in the bar
> template function (like a missing semicolon).
Ideally, you would catch this in the unit tests for `bar`. You
are writing unit tests, aren't you? ;)
More information about the Digitalmars-d
mailing list