/* Example programs from the book Scientific and Engineering Programming in C++: An Introduction with Advanced Techniques and Examples, Addison-Wesley, 1994. (c) COPYRIGHT INTERNATIONAL BUSINESS MACHINES CORPORATION 1994. ALL RIGHTS RESERVED. See README file for further details. */ #include "Array/ArrayTuplize.h" template Array2d& Array2d::operator=(const ConstArray2d& rhs) { Subscript i = shape(0); if (i != rhs.shape(0)) throw ArrayErr::Shape(); while (i-- > 0) (*this)[i] = rhs[i]; return *this; } template Array2d& Array2d::operator=(const T& rhs) { Subscript i = shape(0); while (i-- > 0) (*this)[i] = rhs; return *this; } template ostream& operator<<(ostream& os, const ConstArray2d& a) { return arrayTuplize(a, os); } template istream& operator>>(istream& is, Array2d& a) { char c = 0; is >> c; if (c == '[') { Subscript n = a.shape(0); Subscript i = 0; while ( i < n ) { Array2d::ProjectionT a_i = a[i]; is >> a_i; if (!is.good()) break; is >> c; i++; if ( i == n ) { if (c != ']') is.clear(ios::badbit); } else { if (c != ',') is.putback(c); } } } else { is.putback(c); is.clear(ios::badbit); } return is; } template ConstArray2d::ConstProjectionT ConstArray2d::operator[](Subscript i) const { return project(i, 0); } template ConstArray2d::ConstProjectionT ConstArray2d::row(Subscript i) const { return project(i, 0); } template ConstArray2d::ConstProjectionT ConstArray2d::column(Subscript i) const { return project(i, 1); } template Array2d::ConstProjectionT Array2d::operator[](Subscript i) const { return project(i, 0); } template Array2d::ConstProjectionT Array2d::row(Subscript i) const { return project(i, 0); } template Array2d::ConstProjectionT Array2d::column(Subscript i) const { return project(i, 1); } template Array2d::ProjectionT Array2d::operator[](Subscript i) { return project(i, 0); } template Array2d::ProjectionT Array2d::row(Subscript i) { return project(i, 0); } template Array2d::ProjectionT Array2d::column(Subscript i) { return project(i, 1); }