changeset 28645:175eedccc085

define mixed-type operators for octave_idx_type and octave_int<T> values * oct-inttypes.h: Define templates for +, -, *, and / operators for octave_idx_type and octave_int<T> arguments.
author John W. Eaton <jwe@octave.org>
date Thu, 20 Aug 2020 17:42:26 -0400
parents ef0775fdab2c
children e26201931ea3
files liboctave/util/oct-inttypes.h
diffstat 1 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/util/oct-inttypes.h	Thu Aug 20 17:40:47 2020 -0400
+++ b/liboctave/util/oct-inttypes.h	Thu Aug 20 17:42:26 2020 -0400
@@ -1330,4 +1330,29 @@
   return octave_int<T> (xv <= yv ? xv : yv);
 }
 
+// Ints are handled by converting to octave_int type.
+
+#define OCTAVE_INT_IDX_TYPE_BIN_OP(OP)                          \
+  template <typename T>                                         \
+  inline octave_int<T>                                          \
+  operator OP (const octave_int<T>& x, octave_idx_type y)       \
+  {                                                             \
+    return x OP octave_int<T> (y);                              \
+  }                                                             \
+                                                                \
+  template <typename T>                                         \
+  inline octave_int<T>                                          \
+  operator OP (octave_idx_type x, const octave_int<T>& y)       \
+  {                                                             \
+    return octave_int<T> (x) OP y;                              \
+  }
+
+OCTAVE_INT_IDX_TYPE_BIN_OP (+)
+OCTAVE_INT_IDX_TYPE_BIN_OP (-)
+OCTAVE_INT_IDX_TYPE_BIN_OP (*)
+OCTAVE_INT_IDX_TYPE_BIN_OP (/)
+
+#undef OCTAVE_INT_IDX_TYPE_BIN_OP
+
+
 #endif