template warning message that will *never* effect compilation
monkyyy
crazymonkyyy at gmail.com
Tue Feb 4 23:31:30 UTC 2025
Contracts, the ooness of `std.range.interfaces`, several traits
are about attempting to control the correctness of templates; I
say all'y'alls should give it all up entirely make the dumbest
thing possible. However such code will make terrible, terrible
template error messages, the more used and nested, the worse
those error message get
If you add dumby functions currently it will effect trait compiles
```d
import std;
void foo()(){
static assert(0,"foo is fundmentally incorrect, consider using
bar instead");
}
void callifpossible(alias F)(){
static if(__traits(compiles,F)){
F();
} else {
"WARN: this didnt actaully compile, but managed to run".writeln;
}}
unittest{
callifpossible!foo;//fails
}
```
Suppose you wanted to add a warning to filter that length "cant
be defined, consider adding something that caches the output",
that function will likely work like foo from that example code
and by having it there your interducing interspersion liability's
and generate new exciting problems.
---
```d
struct filter{
throw template length() "filter.length can not be defined";
}
```
add it behind a verbose compile flag, define such code as unable
to effect compilation; maybe it will make template hell have
better error messages
More information about the dip.ideas
mailing list