My template tuple code does not compile
Q. Schroll
qs.il.paperinik at gmail.com
Tue Feb 26 22:51:15 UTC 2019
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?
I cannot tell you, why exactly you get these error messages. I
can explain you the probable cause of the errors. I have not
tested anything of what I tell you, as it is very vague.
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.
More information about the Digitalmars-d-learn
mailing list