First Draft: Implicit Conversion of Template Instantiations
Timon Gehr
timon.gehr at gmx.ch
Mon Mar 18 00:32:35 UTC 2024
On 3/16/24 16:50, Walter Bright wrote:
> https://github.com/WalterBright/documents/blob/9dba63a4c2887bdb2b988c354ebb0d6bb44c4968/templatecast.md
>
> DConf: https://dconf.org/2024/online/index.html#walterb
In general: Yes, I think something along those lines would be great.
From my DConf question:
```d
struct S(alias a){
void f(){
a();
}
}
void main(){
import std.stdio;
S!({ writeln("first"); }) s1;
S!({ writeln("second"); }) s2 = s1; // ok
s1.f(); // first
s2.f(); // second
pragma(msg, is(typeof(s1):typeof(s2))); // true
}
```
I think this is a bit dangerous. (And on stream you seemed to argue that
this has the potential to kill the proposal.)
I think the way to fix it would be to simply use a more strict standard
than "must belong to the same template". Add an opt-in annotation to
template parameters that indicates "this parameter may change in a const
conversion". For other parameters, you still require them to match by
default.
This way, people can opt into the behavior.
More information about the dip.development
mailing list