AFF --- A container for numbers (array) by Friederich and Forbriger.

◆ operator<<()

template<class T >
std::ostream& operator<< ( std::ostream &  os,
const aff::ConstArray< T > &  a 
)

print values of an NxM array

This operator function can be used as an output operator for aff::Array and aff:ConstArray objects. It silently assumes that the passed array has only two dimensions. It then uses formatted stream output to display the contents of the array.

The function in particular demonstrates the use of array member functions size, first, and last in order to query the index value ranges for the two dimensions in use.

Definition at line 104 of file arrayexample.cc.

105 {
106  // size of array dimensions
107  int N=a.size(0);
108  int M=a.size(1);
109 
110  // report size of array
111  cout << "Elements (i,j) of " << N << "x" << M << " array:" << endl;
112 
113  // width of first column, where value of i will be printed
114  const int firstwidth=6;
115  // width of columns:
116  int columnwidth=(78-firstwidth)/M;
117 
118  // print column headings
119  cout.width(firstwidth);
120  cout.setf(std::ios_base::left, std::ios_base::adjustfield);
121  cout << "";
122  for (int j=a.first(1); j<=a.last(1); j++)
123  {
124  cout << "j=";
125  cout.width(columnwidth-2);
126  cout.setf(std::ios_base::left, std::ios_base::adjustfield);
127  cout << j;
128  }
129  cout << endl;
130 
131  // print contents of array
132  // outer loop: first index
133  for (int i=a.first(0); i<=a.last(0); i++)
134  {
135  cout << "i=";
136  cout.width(firstwidth-2);
137  cout.setf(std::ios_base::left, std::ios_base::adjustfield);
138  cout << i;
139  // inner loop: second index
140  for (int j=a.first(1); j<=a.last(1); j++)
141  {
142  cout.width(columnwidth);
143  cout << a(i,j);
144  }
145  cout << endl;
146  }
147  return os;
148 } // std::ostream& operator<<(std::ostream& os, const aff::ConstArray<T>& a)
Tsize size() const
total number of mapped elements
Definition: strided.cc:140
const Tsubscript & last(const Tsubscript &i) const
last index of dimension
Definition: strided.h:197
const Tsubscript & first(const Tsubscript &i) const
access to base class function
Definition: strided.h:194