[Issue 24307] New: [std.meta] weak values/alias for default values

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 29 23:19:56 UTC 2023


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 at puremagic.com
          Reporter: crazymonkyyy at 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

--


More information about the Digitalmars-d-bugs mailing list