Trouble creating a formatted assert wrapper

Jonathan M Davis jmdavisProg at gmx.com
Mon Sep 3 04:49:57 PDT 2012


On Monday, September 03, 2012 11:25:05 Peter Alexander wrote:
> On Monday, 3 September 2012 at 09:15:08 UTC, Chris
> 
> Nicholson-Sauls wrote:
> > On Sunday, 2 September 2012 at 23:40:01 UTC, Peter Alexander
> > 
> > wrote:
> >> Consider:
> >> 
> >> myAssert(false, "%d", 1);
> >> 
> >> What is Args? "%d", 1 could refer to the optional arguments,
> >> or the variadic arguments. Both match.
> > 
> > Easy: the variadic arguments are not, themselves, optional.
> > Match the variadic.  This kind of problem is already solved in
> > every language with "scattering" assignments, and other such
> > features.
> 
> The variadic arguments are optional, as you can have zero
> arguments count as variadic.

You can use a template constraint if you want to require that there be at 
least a certain number of arguments. Also, if you know that there always needs 
to be at least a certain number of arguments, then you can simply make it so 
that the required ones are non-variadic. e.g.

void func(A, B, C...)(A a, B b, C cs)
{
    ...
}

> Also, how can I override the optional arguments in this function
> if all arguments are matched as variadic?

Use template constraints.

- Jonathan M Davis


More information about the Digitalmars-d mailing list