December 29, 2023 [Issue 24307] New: [std.meta] weak values/alias for default values | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24307 Issue ID: 24307 Summary: [std.meta] weak values/alias for default values Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: enhancement Priority: P1 Component: phobos Assignee: nobody@puremagic.com Reporter: crazymonkyyy@gmail.com when writing naive template code with default values those default values are required to match the types of the generated function (id argue erroneously) ```d auto lerp(I,F)(I a,I b,F per=.5){} struct myfloat{} void main(){ lerp(1,10,myfloat()); } ``` > cannot implicitly convert expression `0.5` of type `double` to `myfloat` Its possible to solve this with 5 lines of template code and an uglier header, without the trade-offs of limiting the types accepted or mandating a full argument list, but it is tricky and writing the header to use the code would probably require an explanation my code for reference: https://gist.github.com/crazymonkyyy/b8793bd95afb86092944104531eecd56 Id suggest merging `weak` either as is or under the name "WeakAlias"/"WeakValue" if you must be verbose maybe consider if its possible to discard errors, but I didnt find a way to do so -- |
Copyright © 1999-2021 by the D Language Foundation