https://issues.dlang.org/show_bug.cgi?id=24039

--- Comment #2 from Bolpat <qs.il.paperi...@gmail.com> ---
(In reply to Dennis from comment #1)
> If I understand correctly, you want the compiler to rewrite
> `1.opBinary!"+"(2)` to `1 + 2` for meta-programming. Can you give an example
> where you want to use this, instead of just the + operator?

I don’t want to write `1.opBinary!"+"(2)` directly, there’s clearly not much
use for this, but I definitely want to be able to use the `hasMember` trait or
something like that. It makes it easier to forward operations as well
(currently, you need a mixin). With `opBinary` (and `opUnary`), it’s rather
unspecific, but think of `opCall`, `opIndex`, `opEquals` or `opCmp`.

Just imagine how much clearer template code becomes when the question “Does
this support comparison?” is exactly identical to “Is there a member `opCmp`?”.
Same for `opEquals`. Same for `opCall`.

It’s mostly about consistency and lowering the mental burden. Ideally, built-in
types are as un-special as possible. If built-in types behaved like
user-defined types, there should be those member functions.

I stumbled into this when attempting to write a trait to find out if a type has
partial comparison, i.e. has values that are neither ≤ nor ≥. Ideally, you
check the result of `opCmp`, but no, there’s so many built-in types that I’m
never really sure I handled all.

--

Reply via email to