From 128880ea1daf64a3701a77420159eb32af536b39 Mon Sep 17 00:00:00 2001 From: Jason Stewart Date: Thu, 3 Apr 2008 11:40:20 +0000 Subject: [PATCH] added __rsub__() and test for reversed subtraction operator git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10337 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Examples/test-suite/operator_overload.i | 3 +++ Examples/test-suite/perl5/operator_overload_runme.pl | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Examples/test-suite/operator_overload.i b/Examples/test-suite/operator_overload.i index d618fa6b2..b2748f9b4 100644 --- a/Examples/test-suite/operator_overload.i +++ b/Examples/test-suite/operator_overload.i @@ -183,6 +183,9 @@ inline bool operator>=(const Op& a,const Op& b){return a.i>=b.i;} bool operator> (const Op& b){return $self->i>b.i;} bool operator>=(const Op& b){return $self->i>=b.i;} + // subtraction with reversed arguments + Op __rsub__(const int b){return Op(b - $self->i);} + // we also add the __str__() fn to the class // this allows it to be converted to a string (so it can be printed) const char* __str__() diff --git a/Examples/test-suite/perl5/operator_overload_runme.pl b/Examples/test-suite/perl5/operator_overload_runme.pl index 3d87c6ecb..ba3f33a64 100644 --- a/Examples/test-suite/perl5/operator_overload_runme.pl +++ b/Examples/test-suite/perl5/operator_overload_runme.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 38; +use Test::More tests => 39; use operator_overload; @@ -66,6 +66,11 @@ $op2->{i} = 3; $op = $op3 - $op2; is($op->{i}, 3, "operator subtraction"); +# reversed subtraction operator (with int) +$op3->{i} = 3; +$op = 6 - $op3; +is($op->{i}, 3, "reversed operator subtraction (with int)"); + # subtractive assignment operator $op->{i} = 6; $op2->{i} = 3;