Shortcomings of D-Style Fused Operator Overloading

deadalnix deadalnix at gmail.com
Fri Jul 7 16:18:56 UTC 2023


On Friday, 7 July 2023 at 09:18:38 UTC, Ahmet Sait wrote:
> Let's define two intervals x and y:
> {x ∈ ℝ │ a ≤ x ≤ b}
> {y ∈ ℝ │ c ≤ y ≤ d}
>
> And the inequality operators:
> ```
> x < y = ⎧ 1  if b < c
>>         ⎩ 0  otherwise
>
> x ≤ y = ⎧ 1  if b ≤ c
>>         ⎩ 0  otherwise
>
> x > y = ⎧ 1  if a > d
>>         ⎩ 0  otherwise
>
> x ≥ y = ⎧ 1  if a ≥ d
>>         ⎩ 0  otherwise
> ```
>
> Exercise: Write an `opCmp()` method that implements the rules 
> above for `struct Interval { int lower, upper; }`. (Hint: It's 
> not possible.)
>

Thanks god. If you are doing something non standard, do not use 
the builtin operators, give you operation an explicit name.



More information about the Digitalmars-d mailing list