aboutsummaryrefslogtreecommitdiff
path: root/src/jtutil/test_array2.cc
diff options
context:
space:
mode:
authorjthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5>2002-04-07 14:17:33 +0000
committerjthorn <jthorn@f88db872-0e4f-0410-b76b-b9085cfa78c5>2002-04-07 14:17:33 +0000
commit6b4191b3208a563102e5278b49c4c4a0e2092704 (patch)
treebb9c2a9f1fa45c91b971ea6600baab1853d4a5e2 /src/jtutil/test_array2.cc
parentec7974cd2a9ed540cc0022e365a13ff961c128aa (diff)
change rvalue operator() fns to return const references to array data
so they can be used in unary address-of expressions eg const jtutil::array2d<double> A(...) const double *pij = &A(i,j); also add test program for this git-svn-id: http://svn.einsteintoolkit.org/cactus/EinsteinAnalysis/AHFinderDirect/trunk@458 f88db872-0e4f-0410-b76b-b9085cfa78c5
Diffstat (limited to 'src/jtutil/test_array2.cc')
-rw-r--r--src/jtutil/test_array2.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/jtutil/test_array2.cc b/src/jtutil/test_array2.cc
new file mode 100644
index 0000000..555c684
--- /dev/null
+++ b/src/jtutil/test_array2.cc
@@ -0,0 +1,56 @@
+// test_array2.cc -- test driver for array.hh classes
+// $Id$
+
+#include <assert.h>
+#include <math.h>
+#include <stdio.h>
+
+#include "jt/stdc.h"
+#include "jt/util.hh"
+#include "jt/array.hh"
+
+void print( jtutil::array2d<double>& Aref);
+void cprint(const jtutil::array2d<double>& Aref);
+
+int main()
+{
+const int imin = 3, imax = 7, jmin = 10, jmax = 12;
+jtutil::array2d<double> A(imin,imax, jmin,jmax);
+
+ for (int i = imin ; i <= imax ; ++i)
+ {
+ for (int j = jmin ; j <= jmax ; ++j)
+ {
+ A(i,j) = i*j;
+ }
+ }
+
+ print(A);
+cprint(A);
+}
+
+void print(jtutil::array2d<double>& Aref)
+{
+printf("=== nonconst ===\n");
+ for (int i = Aref.min_i() ; i <= Aref.max_i() ; ++i)
+ {
+ for (int j = Aref.min_j() ; j <= Aref.max_j() ; ++j)
+ {
+ printf("Aref(%d,%d) = %g at address %p\n",
+ i, j, Aref(i,j), &Aref(i,j));
+ }
+ }
+}
+
+void cprint(const jtutil::array2d<double>& Aref)
+{
+printf("=== const ===\n");
+ for (int i = Aref.min_i() ; i <= Aref.max_i() ; ++i)
+ {
+ for (int j = Aref.min_j() ; j <= Aref.max_j() ; ++j)
+ {
+ printf("Aref(%d,%d) = %g at address %p\n",
+ i, j, Aref(i,j), &Aref(i,j));
+ }
+ }
+}