Capturing caller's file/line number in variadic template functions
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Mar 16 11:37:55 PDT 2012
On Fri, Mar 16, 2012 at 02:31:47PM -0400, Kevin Cox wrote:
> On Mar 16, 2012 2:29 PM, "Adam D. Ruppe" <destructionator at gmail.com> wrote:
> >
> > Put the string file = blaha in the template argument list,
> > before the variadic.
> >
> > voic checkConsistency(string file = __FILE__, int line = __LINE__,
> T...)(T t) {
> >
> >
> But then you have to write it each time.
No you don't. The compiler automatically infers the compile-time
arguments for you. This works:
int a;
char b;
float c;
checkConsistency(a,b,c);
// Gets translated to:
checkConsistency!(__FILE__, __LINE__, int, char, float)(a,b,c);
exactly as I wanted.
T
--
People say I'm arrogant, but they're just ignorant fools.
More information about the Digitalmars-d-learn
mailing list