head	1.1;
access;
symbols;
locks; strict;
comment	@// @;


1.1
date	94.09.02.02.43.28;	author rjj;	state Exp;
branches;
next	;


desc
@These files are of historical interest for UM v1.0.
@


1.1
log
@Initial revision
@
text
@// Emacs: -*- C++ -*-

// valueset_example.03       Value set of not totally ordered types

#include <complex.h>
#include "ValueSet.h"

// Since the type   complex  DOES NOT SUPPORT operator< or operator>
// it is not possible to create a IA_ValueSet<complex> without some
// additional work.  It is necessary to define a specialization for
// the base class IA_ValueSetComparator<> before such a value set
// can be constructed.

// Specialize IA_ValueSetComparator<T> for complex
class  IA_ValueSetComparator<complex> {
    static int value_type_compare(const void* lhs, const void* rhs) {
	complex
	    clhs(*((const complex*) lhs)),
	    crhs(*((const complex*) rhs));

	if (real(clhs) == real(crhs)) {
	    if (imag(clhs) == imag(crhs)) {
		return 0;
	    }
	    else {
		return (imag(clhs) < imag(crhs)) ? 1 : -1;
	    }
	} else {
	    return (real(clhs) < real(crhs)) ? 1 : -1;
	}
    }
};


main() {

// Create a vector of complex values for the value set constructor
    complex vec[] = { complex(-3.0l,-3.0l), complex(-2.0l,-2.0l),
		      complex(-1.0l,-1.0l), complex(0.0l,0.0l),
		      complex(1.0l,1.0l),   complex(2.0l,2.0l),
		      complex(3.0l,3.0l) };

    IA_Set<complex>
	vs1( complex(-1.0,-1.0), complex(-1.0,0.0),
	     complex(0.0,0.0), complex(0.0,-1.0)),
	vs2(vec, 7),	// vs2 has the unique elements drawn from the
			// 7 element array called vec.
	vs3;

    vs3 = vs1 | vs2;	// union is represented by the logical OR symbol |

    cout << "vs1 has value " << vs1 << "\n";
    cout << "vs2 has value " << vs2 << "\n";
    cout << "vs3 has value " << vs3 << "\n";
}
@
