digitalmars.D.learn - How to do operator overloading for <, >, <=, >=, !=, and == between
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (9/9) Apr 21 2019 I am writing an opencv binding and need something like: Mat m =
- Adam D. Ruppe (11/13) Apr 21 2019 D does not support that. The comparison operators are always just
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (3/17) Apr 21 2019 I am a little disappointed :( I will go for named method instead.
I am writing an opencv binding and need something like: Mat m = another_mat > 5; Docs does not cover this sitiuation: https://dlang.org/spec/operatoroverloading.html#compare opBinary does not support those operators, and Section "Overloading <, <=, >, and >=" describes overloaded operators returning only int values. My struct is defined here: https://github.com/aferust/opencvd/blob/master/source/opencvd/cvcore.d
Apr 21 2019
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.
Apr 21 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 a little disappointed :( I will go for named method instead. Thank you for a fast response.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.
Apr 21 2019