Thread overview | |||||
---|---|---|---|---|---|
|
December 30, 2023 [Issue 24307] [std.meta] weak values/alias for default values | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24307 Basile-z <b2.temp@gmx.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |b2.temp@gmx.com --- Comment #1 from Basile-z <b2.temp@gmx.com> --- There are language tricks that can be used too, for example "uniform construction syntax" ```d auto lerp(F = double, I)(I a,I b,F per=F(.5)){} struct myfloat{double v;} void main(){ lerp(1,10,myfloat()); lerp(1,10); lerp!(myfloat)(1,10); } ``` But at some point the fact that D does no implicit construction will still be a limitation. -- |
December 30, 2023 [Issue 24307] [std.meta] weak values/alias for default values | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24307 Dominikus Dittes Scherkl <dominikus@scherkl.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dominikus@scherkl.de --- Comment #2 from Dominikus Dittes Scherkl <dominikus@scherkl.de> --- If something doesn't convert implicitly, do it explicitly: ```d auto lerp(I,F)(I a,I b,F per=F(.5)){} struct myfloat{} void main(){ lerp(1,10,myfloat()); } ``` Of course then F need to have a fitting constructor. Or an opCast: ```d auto lerp(I,F)(I a,I b,F per=cast(F).5){} struct myfloat{} void main(){ lerp(1,10,myfloat()); } ``` -- |
December 30, 2023 [Issue 24307] [std.meta] weak values/alias for default values | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24307 --- Comment #3 from crazymonkyyy@gmail.com --- thats a simplified example, feel free to get get a more complex version working with only languge features but I'd want some helper code ```d float lerpammount=.5; auto lerp(I,F=typeof(lerpammount))(I a,I b,F per=weak!(F,lerpammount)){ import std; writeln(a," ",b," ",per); } auto remap(T,S=float)(T v,T min1=weak!(T,T.min),T max1=weak!(T,T.max),S min2=weak!S(0.0),S max2=weak!S(1.0)){ import std; writeln(v," ",min1," ",max1," ",min2," ",max2); } struct myfloat{} struct myint{ int i; enum min=myint(0); enum max=myint(100); } void main(){ lerp(1,10); lerp(1,10,myfloat()); lerpammount=.9; lerp(1,10); lerp(myint(),myint()); remap(ubyte(128)); remap(ubyte(167),ubyte(128)); remap(5,0,10); remap(5,0,10,.5); remap(myint()); remap(5,0,10,myint(100),myint(0)); } ``` which is simplier than my use case where I finally used `void drawtext(/*T,*/I,J=int,C=typeof(text),C2=typeof(highlight)) (string text_,I x,I y,J textsize=weak!J(16),C color=weak!(C,text),C2 color2=weak!(C2,highlight)){` where these color tooltips are very very ugly types -- |
Copyright © 1999-2021 by the D Language Foundation