Object.toString, toHash, opCmp, opEquals

Timon Gehr timon.gehr at gmx.ch
Fri Apr 26 23:30:45 UTC 2024


On 4/26/24 22:23, Walter Bright wrote:
> On 4/26/2024 7:00 AM, Timon Gehr wrote:
>> This is not a theoretical problem either. This kind of introspection 
>> would be the proper fix for the following issue with 
>> std.typecons.Tuple.toString:
>>
>> ```d
>> import std.stdio, std.typecons;
>> class C{
>>      override string toString()=>"correct";
>> }
>>
>> void main(){
>>      writeln(new C()); // "correct"
>>      writeln(tuple(new C())); // "Tuple!(C)(const(tt.C))"
>> }
>> ```
>>
>> This is also the same issue that prevents tuples with range members 
>> from being printed properly.
> 
> I would like to see "new C()" and "tuple(new C())" mean exactly the same 
> thing. After all, with the builtin-tuples (not the struct library 
> version) they are the same thing.
> 

Ok, then I will further pursue an implementation of `opArgs` I guess. It 
does have a couple of drawbacks, but if this is your preference we can 
try to make it work.


More information about the Digitalmars-d mailing list