Capturing caller's file/line number in variadic template functions

Steven Schveighoffer schveiguy at yahoo.com
Fri Mar 16 11:30:25 PDT 2012


On Fri, 16 Mar 2012 14:23:37 -0400, H. S. Teoh <hsteoh at quickfur.ath.cx>  
wrote:

> 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 know this is already answered, but do you get a stack trace?  Shouldn't  
the second stack frame point to the offending line?

-Steve


More information about the Digitalmars-d-learn mailing list