Object.toString, toHash, opCmp, opEquals
    An Pham 
    home at home.com
       
    Thu Jun  6 20:03:09 UTC 2024
    
    
  
>
> I talked to Walter and we agreed that the best way forward is 
> probably to deprecate these member functions and remove them in 
> the next edition.
What are the problems when getting rid all of them?
Currently, below codes are compiled with correct result, why not 
emulated without those functions?
struct F
{
     string s;
     int i;
}
void main()
{
     import std.conv : to;
     F f1 = {s:"1", i:1};
     F f2 = {s:"2", i:2};
     const c = int.min; // f2 > f1; onlineapp.d(13): Error: need 
member function `opCmp()` for struct `F` to compare
     const e = f2 == f1;
     const s = f2.to!string;
     const h = hashOf(f2); // f2.toHash(); onlineapp.d(16): Error: 
no property `toHash` for `f2` of type `onlineapp.F`
     import std.algorithm, std.stdio, std.file, std.range;
     writeln("c=", c, ", e=", e, ", s=", s, ", h=", h);
}
    
    
More information about the Digitalmars-d
mailing list