Capturing caller's file/line number in variadic template functions
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Mar 16 11:23:37 PDT 2012
I'm writing some unittests with very repetitive tests for a myriad of
different types, so I wrote a helper function:
version(unittest) {
void checkConsistency(T...)(T args) {
foreach (a; args) {
assert(isConsistent(a));
}
}
}
unittest {
A a;
B b;
C c;
checkConsistency(a,b,c);
}
However, when a consistency check fails, the assert error points to
checkConsistency instead of the unittest, so it's a pain trying to
figure out exactly which test case failed. I tried adding default
arguments to checkConsistency:
void checkConsistency(T...)(T args, string file=__FILE__,
size_t line=__LINE__) { ... }
but this causes compile errors because when C==string, then the call is
ambiguous.
Is there an easy of working around this?
T
--
To err is human; to forgive is not our policy. -- Samuel Adler
More information about the Digitalmars-d-learn
mailing list