/* 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/FormedArray1d.h" #include "SciEng/EquivalentCategory.h" template class ComparableFormedArray1d : public FormedArray1d, public EquivalentCategory< ComparableFormedArray1d > { public: ComparableFormedArray1d(Subscript n); ComparableFormedArray1d(const FormedArray1d& f); // ... virtual Array1d& operator=(const ConstArray1d&); virtual Array1d& operator=(const T&); // User Must Define for EquivalentCategory Boolean equivalentTo(const ComparableFormedArray1d&) const; }; template ComparableFormedArray1d::ComparableFormedArray1d(Subscript n) : FormedArray1d(n){} template ComparableFormedArray1d::ComparableFormedArray1d(const FormedArray1d& f) : FormedArray1d(f){} template Array1d& ComparableFormedArray1d::operator=(const T& rhs) { return FormedArray1d::operator=(rhs); } template Array1d& ComparableFormedArray1d::operator=(const ConstArray1d& rhs) { return FormedArray1d::operator=(rhs); } template Boolean ComparableFormedArray1d::equivalentTo(const ComparableFormedArray1d& rhs) const { if (shape(0) != rhs.shape(0) ) return Boolean::false; for (Subscript i = shape(0)-1; i >= 0; i--) { if ((*this)(i) != rhs(i)) return Boolean::false; } return Boolean::true; } int main() { ComparableFormedArray1d a(4); ComparableFormedArray1d b(4); // Set elements of a and b... a = 3; b = 2; if ( a == b ) { // ... } // ... if ( a != b ) { // ... } if (!(a == b) && (a != b)) return 0; return 1; }