My Little Dustmite: Bisect is Magic

Bastiaan Veelo Bastiaan at Veelo.net
Sat Jul 27 22:55:48 UTC 2019


On Saturday, 27 July 2019 at 22:22:57 UTC, Ethan wrote:
> On Saturday, 27 July 2019 at 22:19:20 UTC, Bastiaan Veelo wrote:
>> If continuing is desired, would a `static if` combined with 
>> `pragma (msg, ...)` not be more appropriate than `static 
>> assert`? This can probably go into a ct function like 
>> `static_check`.
>>
>> Bastiaan.
>
> I was considering making that point myself. The static assert 
> here is kinda useless, a pragma( msg ) won't stop compilation.
>
> This is in that weird <non-PC word> area that people keep 
> bringing up. The recommended course of development with 
> templates is to static assert with your own handy error 
> message. The reality is that you lose vital information about 
> why that template is not instantiating unless you litter your 
> code with static ifs and pragma( msg )s.

Tossing in a `version` may produce a helpful idiom, if 
compilation should continue during lib dev and stop during lib 
usage:

```
import std;

void my_static_assert(alias condition, string message)()
{
     version(continue_past_assert)
     {
         static if (!condition)
             pragma(msg, message);
     } else {
         static assert(condition, message);
     }
}

void main()
{
     my_static_assert!(false, "fix your mistake");
     writeln("Hello D");
}
```

https://run.dlang.io/is/5NqYj7


More information about the Digitalmars-d mailing list