[Issue 24307] [std.meta] weak values/alias for default values
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Dec 30 16:52:15 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=24307
--- Comment #3 from crazymonkyyy at 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
--
More information about the Digitalmars-d-bugs
mailing list