opCmp with template type not working.
Paul Backus
snarwin at gmail.com
Sun Nov 8 14:38:43 UTC 2020
On Sunday, 8 November 2020 at 12:52:14 UTC, Dominikus Dittes
Scherkl wrote:
>
> Yeah, but int is 32 bit, same as float. So why use a type that
> restricts the use cases without any benefit?
For types that are totally ordered, it's easier for the user if
they don't have to consider the possibility that opCmp will
return NaN.
> Simply always use float, so you have no changes if you later
> detect that your type to compare is in fact _not_ totally
> ordered (e.g. has some special cases). And beliefe me, for most
> types you will earlier or later detect, that they are not
> totally ordered.
I'm skeptical of the idea that "most" types are partially
ordered, but even if they are, so what? The only code that will
break if you change the return type of opCmp from int to float
after the fact is code that's calling `.opCmp` directly--and you
probably *want* that code to break if you're switching from a
total order to a partial one.
More information about the Digitalmars-d
mailing list