Bug 19299 – string mixins and template mixins should be allowed in function parameter list

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2018-10-11T07:29:57Z
Last change time
2024-12-13T19:00:50Z
Assigned to
No Owner
Creator
Simen Kjaeraas
See also
https://issues.dlang.org/show_bug.cgi?id=2624
Moved to GitHub: dmd#19493 →

Comments

Comment #0 by simen.kjaras — 2018-10-11T07:29:57Z
Inspired by https://forum.dlang.org/post/[email protected] It would be nice if phobos had a CopyParameters template, which copies both parameter types and -names, such that this compiles: void fun(int a, string s); void gun(mixin CopyParameters!fun) { a = 3; s = "foo"; } When I do this today, the error message says 'basic type expected, not mixin'. The feature should for string mixins: void foo(mixin("int x")) {} And for template mixins: void bar(mixin tmp!()) {} template tmp() { int a; }
Comment #1 by nick — 2023-07-31T11:59:10Z
Just to mention, you can copy parameters like this: ```d // simpler version of std.traits.Parameters (which also works) template Params(alias func) { static if (is(typeof(func) PS == __parameters)) alias Params = PS; } void f(Params!g, int extra); void g(char c = 0, byte b); pragma(msg, typeof(f)); ``` If you need just one parameter, use slicing `PS[i..i+1]` rather than indexing and it will preserve not just the type but the identifier and default argument too.
Comment #2 by nick — 2023-07-31T12:46:50Z
Actually std.traits.Parameters does not work, it is just the parameter types. The pragma above prints: void(char c = '\0', byte b, int extra) (Even though the default argument can't be followed by non-default args!).
Comment #3 by robert.schadek — 2024-12-13T19:00:50Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19493 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB