operator-overloading icon indicating copy to clipboard operation
operator-overloading copied to clipboard

operator overload with assigment?

Open ghost opened this issue 9 years ago • 5 comments

hello, have you support operator overload with assigment?

ghost avatar Aug 16 '16 23:08 ghost

@acterhd the operator overloading rewrites x += y as x = x + y automatically. Overriding + should be enough to implement both + and +=.

k4b7 avatar Aug 17 '16 03:08 k4b7

I suggest two unary operators: "&" and "|", that for SIMD means "allTrue" and "anyTrue".

ghost avatar Aug 20 '16 12:08 ghost

I thought & and | were bitwise AND and bitwise OR. Are you suggesting that defining & should automatically define &= as x = x & y?

k4b7 avatar Aug 23 '16 19:08 k4b7

I've personally think that the best option override operator considers the three-operand. And the first operand, where he also gets the result (at least temporarily) does not mean assigment.

overload("+", [OutClass, InClassL, inClassR], function(where, left, right){
  if(where == null) {
    where = new OutClass();
  }
  left.addAs(where, right); 
  return where; 
});

I think this approach is more natural to the assembly point of view.

overload("++", [OutClass, InClassL], function(where/*, left*/){
  let clone = where.clone();
  where.some++;
  return clone; 
});

And for example a += b, means that assigned to a, and returned a.

ghost avatar Aug 26 '16 12:08 ghost

Isn't OutClass === InClassL always? Am I missing something?

k4b7 avatar Aug 30 '16 01:08 k4b7