Two things I thought would be simple

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Mar 7 17:23:40 UTC 2018


On Wednesday, March 07, 2018 18:59:51 Shachar Shemesh via Digitalmars-d 
wrote:
> On 07/03/18 16:42, Jonathan M Davis wrote:
> > AFAIK, there's no way to get the values of default arguments with type
> > inferrence
>
> I used that way right there in the code. ParameterDefaults!func return a
> tuple with the arguments. The problem is that "Tuple var = Tuple" does
> not work. Different errors for when all the original function's
> arguments have default and when some don't, but don't work either way.

Then clearly I read your code too quickly. Looking it over, there are
several problems here. First off, regardless of what's going on with the
default arguments, you made the functions return void instead of int or
auto, meaning that even

void func2(Parameters!func args)
{
     return func(args);
}

fails to compile. With that fixed, it works so long as you pass all of the
arguments. With

auto func2(Parameters!func args = ParameterDefaults!func)
{
     return func(args);
}

it doesn't work, because apparently, ParameterDefaults gives void if there
is no default argument, which makes sense, but makes what you're trying to
do not work. Either every parameter needs a default argument, or a wrapper
template that filled in the init value for the missing default argument
would be necessary. However, even doing something like

auto func2(Parameters!func args = AliasSeq!(1, 2, 3))
{
     return func(args);
}

doesn't work properly. If that version of the function is used, then the
call which passes all three arguments compiles, but the others don't, which
means that it's acting like the AliasSeq isn't even there (though it's
clearly doing _something_ with it, since you get a compilation error if one
of its values is void). I'd argue that either the values in the AliasSeq
should be being assigned, or they shouldn't be legal. Having them be there
but ignored just plain seems like a bug, but I have no idea what the
compiler is thinking here.

- Jonathan M Davis



More information about the Digitalmars-d mailing list