Why not just add an extra string parameter to constraint functions that will show a custom error message? This kind of works (although you still get standard errors):
import std.conv; import std.stdio; alias int cool; bool isCool(T, string X)() { static if (is(T : cool)) { return true; } else { pragma(msg, "Constraint failure: " ~ X); return false; } } void foo(X)(X x) if (isCool!(X, "foo(X) argument must be cool!")()) { } void main() { cool myvar; double myvar2; foo!()(myvar); foo!()(myvar2); } On 12/11/10, Robert Jacques <sandf...@jhu.edu> wrote: > On Sat, 11 Dec 2010 12:15:31 -0500, Andrei Alexandrescu > <seewebsiteforem...@erdani.org> wrote: > [snip] >> This program will generate a valid executable, but will also print >> during compilation: >> >> Type int is not a random access range because: >> no empty property >> no front property >> no popFront method >> no indexing >> no slicing >> >> When a programmer has an odd issue with a range check, turning >> verboseness of checks could help. >> >> What do you think? >> >> >> Andrei > > An issue with this is that failed template type checks are both extremely > common and expected in template code: i.e. static > if(isRandomAccessRange!T) {...}. So, you'll get a lot of spurious error > messages slowly. Add in parallel builds, and the last error message won't > even be the one you're looking for. So, while I think the concept is > usefully, I'd view this implementation as an intermediate stepping stone > at best (and a distraction from you fixing other bugs at worse). I'd > recommend, as an alternative, to have specific debug versions of the > checks, i.e. isRandomAccessRangeDebug, as a way to avoid false positives. >