-
-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate typesafe variadic class arguments #19890
Comments
They are supported, the problem is that you rely on implicit construction of an A instance which does not exist in D. The correct way to write this is struct A
{
int a;
}
int f(A a...){ return a.a; }
static assert(f(A(4))==4); I think this one can be closed as invalid. |
Implicit construction is supported for class arguments of a typesafe variadic function. class A
{
this(int a) {this.a = a;}
int a;
}
int f(A a...){ return a.a; }
static assert(f(4) == 4); See: https://dlang.org/spec/function.html#typesafe_variadic_functions
So yes, the current compiler behavior is correct, but it makes a variadic struct argument completely useless. You might as well just write: -int f(A a...){ return a.a; }
+int f(A a){ return a.a; } Asking why arrays and classes are supported here, but not structs, is a valid enhancement request. However, Walter has tried to deprecate typesafe variadic arguments before, since D has so many different kinds of variadic functions that it's getting really complex. I think most D users don't even know implicit construction of classes exists, I haven't seen them being used. Perhaps instead of adding typesafe variadic structs, we should deprecate typesafe variadic classes instead. (Removing typesafe variadic arrays received some pushback, since it is being used) |
That is wild!
Yes. |
sorry if I mislead people with my attempt to get this issue closed but in first place, why ? usually implicit construction is not a thing. |
yes, in a first time, then eventually later the whole "type safe variadics"-thing. |
Anyway, after playing with that feature, that's just silly... as you have to define a ctor. I dont understand why this was added to the language. Is that a D1 fossil ? |
anonymous4 reported this on 2021-03-19T19:22:10Z
Transferred from https://issues.dlang.org/show_bug.cgi?id=21736
Description
Typesafe variadic functions are supported with classes, but not with structs. Is there a reason for this limitation?
The text was updated successfully, but these errors were encountered: