My template tuple code does not compile

Victor Porton porton at narod.ru
Tue Feb 26 22:56:37 UTC 2019


On Tuesday, 26 February 2019 at 22:51:15 UTC, Q. Schroll wrote:
> On Tuesday, 26 February 2019 at 21:43:31 UTC, Victor Porton 
> wrote:
>> Compilation of unittest at the bottom of this file fails with 
>> an error. What is my error?
...
> You have the line
>
>    ProviderParams("S", ((int, "x"), (float, "y")));
>
> Why do you even expect it to compile?
> First, ProviderParams is a mixin template, so you'd need to 
> instantiate it with the ! operator. Then, the expressions (int, 
> "x") and so on do not make sense in D. You could have 
> compile-time tuples (using AliasSeq from std.meta) containing 
> types and other compile-time known stuff, but it wouldn't help 
> directly.
> You'd use the mixin template like this:
>
>    mixin ProviderParams!("S", int, "x", float, "y");
>    ^-- necessary       ^-- necessary
>
> Grouping arguments could be done, but from my experience, it 
> does not buy you anything; rather it makes it worse. Better 
> just deal with heterogeneous stuff just like std.typecons.Tuple 
> does.
>
> You should definitely comment your code. Explain what you 
> intend to do. It helps people helping you.

After fixing the error you pointed me, it does not work too:

mixin ProviderParams!("S", ((int, "x"), (float, "y")));

Also: Can I nevertheless group arguments?


More information about the Digitalmars-d-learn mailing list