digitalmars.dip.ideas - template warning message that will *never* effect compilation
- monkyyy (37/37) Feb 04 Contracts, the ooness of `std.range.interfaces`, several traits
- Walter Bright (1/1) Feb 15 I suspect `pragma(msg, "informative message")` will work for that.
- monkyyy (33/35) Feb 15 ```d
- Walter Bright (1/1) Feb 17 You can also add a message to the `static assert(0, "informative message...
- monkyyy (2/4) Feb 17 which will also effect compilation
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
Feb 04
I suspect `pragma(msg, "informative message")` will work for that.
Feb 15
On Saturday, 15 February 2025 at 22:00:40 UTC, Walter Bright wrote:I suspect `pragma(msg, "informative message")` will work for that.```d import std; struct filter{ void popFront(){} enum empty=true; int length()(){//fake length, to provode warning message on use pragma(msg, "informative message"); static assert(0); } } int count(R)(R r){ int i; while(! r.empty){ i++; r.popFront; } return i; } int lengthorcount(R)(R r){//calls length if aviable, otherwise count static if(__traits(compiles,r.length)){ return r.length; } else { return r.count; }} unittest{ int count=filter().count; count=filter().lengthorcount;//fails } ``` it will effect compilation
Feb 15
You can also add a message to the `static assert(0, "informative message")`
Feb 17
On Monday, 17 February 2025 at 08:24:51 UTC, Walter Bright wrote:You can also add a message to the `static assert(0, "informative message")`which will also effect compilation
Feb 17