Operator overloading -- lets collect some use cases
Yigal Chripun
yigal100 at gmail.com
Sun Dec 28 15:14:10 PST 2008
Jarrett Billingsley wrote:
> On Sun, Dec 28, 2008 at 11:50 AM, Don<nospam at nospam.com> wrote:
>
>> So, please post any use cases which you consider convincing.
>
> Virtually all I use it for is making containers. I do almost no
> numerical programming. I would probably not miss much if all I could
> overload were opIndex[Assign], opSlice[Assign], opCat[Assign], and
> opApply.
>
> As you've noted before, overloading of the arithmetic operators isn't
> useful when you only have access to two operands. It seems like an
> AST transformation (macros!) on mathematical transformations into
> possibly-compound operations would be much more useful than plain old
> operator overloading. We're already forced to use expression
> templates to do anything useful with operator overloading; why not put
> a more general, efficient, concise form of that in the language
> itself?
could you please elaborate on this, and/or provide a code example?
Also, just wanted to mention that other languages provide similar
concepts but with slightly different mechanisms - for example, scala
allows to declare a function with two parameters as an infix function,
this idea is also present in functional languages like ML. So my
question therefore is:
what are the pros/cons of limiting this to already existing operators in
the language (similar to C++) vs. allow any kind of symbol and/or
function name?
Downs uses his famous operand1 /func/ operand2 pattern, for example with
a map function. Should D support this in the language?
More information about the Digitalmars-d
mailing list