Standardize base types for metaprogramming

monkyyy crazymonkyyy at gmail.com
Fri Apr 5 18:19:57 UTC 2024


On Friday, 5 April 2024 at 08:57:50 UTC, Dukc wrote:
>  Do you propose that there are some sorts of "alternative 
> .init"s that are universal to all D types? Or is it okay that 
> all the new properties would work for only a subset of D types?
>

I think string.zero should be defined even if its potentially 
nonsense so you can write

```d
auto replaceinvalid(alias F=a=>a==typeof(a).invalid,T)(T 
validate,T replacement=T.zero){
   if(F(validate)){return replacement;}
   return validate;
}
```

Base type can be changed by the user and should be pushed to 
extermes, if users want a function to work they can define the 
requirements with a local enum much like to!string can call 
toString.

If theres some that only work for numbers because the mathy 
poeple make a demand, fine, but I think a 0,1, and invalid that 
applys to all base types would massively help with meta 
programming
0 is theres a throw away value litteral, 1 so you can unittest 
that 0!=1 in data structures, invalid for nullable, unittests, 
missing index etc.


More information about the dip.ideas mailing list