Review: A new stab at a potential std.unittests

Jonathan M Davis jmdavisProg at gmx.com
Fri Nov 19 12:17:54 PST 2010


On Friday 19 November 2010 11:59:18 Sean Kelly wrote:
> Jonathan M Davis Wrote:
> > On Friday, November 19, 2010 11:37:16 Sean Kelly wrote:
> > > Jonathan M Davis Wrote:
> > > > In particular, needing to pass LineInfo() to assertExcThrown!() to
> > > > know the file and line number was disliked (though it was by far the
> > > > best solution that I'd been able to come up with).
> > > 
> > > Not sure if this helps, but if you default-initialize template function
> > > parameters with __LINE__ and __FILE__ they get the line and file of
> > > where the template was instantiated.
> > 
> > Yes. The problem was that the function was a _variadic_ template. So, you
> > couldn't have default arguments.
> 
> This should work:
> 
> void func(string x = __FILE__, T...)(T args);
> 
> D allows defaulted template arguments to occur before non-defaulted ones.

If so, then I obviously assumed that that wouldn't work. You certainly can't do 
that with the function arguments. I think that the new solution is still better 
though, because it allows you to write the function call like you normally 
would. You just have to put it in string form. That, and there were problems 
with passing the function as an alias. Still, it's definitely good to know that 
you can have default template arguments before non-defaulted ones. Thanks.

- Jonathan M Davis


More information about the Digitalmars-d mailing list