How to do operator overloading for <, >, <=, >=, !=, and == between struct and int?

Ferhat Kurtulmuş aferust at gmail.com
Sun Apr 21 18:22:57 UTC 2019


On Sunday, 21 April 2019 at 18:17:00 UTC, Adam D. Ruppe wrote:
> On Sunday, 21 April 2019 at 18:07:08 UTC, Ferhat Kurtulmuş 
> wrote:
>> I am writing an opencv binding and need something like: Mat m 
>> = another_mat > 5;
>
> D does not support that. The comparison operators are always 
> just true or false (as determined by the int opCmp or the bool 
> opEquals returns), they do not return other types.
>
> You will probably have to use a named method instead. You could 
> kinda fake it with a string template arg:
>
> Mat m = another_map.cmp!">"(5);
>
> But I'd probably just do it
>
> Mat m = another_map.is_greater_than(5);
>
> which imo is more readable. but the implementations are the 
> same - in both cases, your custom function.

I am a little disappointed :( I will go for named method instead. 
Thank you for a fast response.


More information about the Digitalmars-d-learn mailing list