Object.toString, toHash, opCmp, opEquals

Timon Gehr timon.gehr at gmx.ch
Fri Apr 26 14:06:02 UTC 2024


On 4/26/24 16:00, 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.

For reference, this is how I deal with problems like that currently:
https://github.com/tgehr/util/blob/master/tuple.d


More information about the Digitalmars-d mailing list