// file weird-less.h
#ifndef __WEIRD_LESS_H_
#define __WEIRD_LESS_H_
#include <cmath>
/* An instance of class WeirdLess is a strict weak order relation object 
 * that illustrates 2 points:
 * 1. Strict weak orderings can be unusual, 
 *    yet work fine with generic order related algorithms.
 * 2. A function object can be made to count how many times it is called, 
 *    useful for measuring and illustrating algorithm analysis.
 * 
 * Intuitively this order relation considers a number to be smaller when farther
 * from one and larger when nearer to one.  The equivalence relation induced by
 * this strict weak ordermakes equivalent each pair of numbers which are the 
 * same distance from one.  For example 0 and 2 are equivalent.  Also -8 and 10 are 
 * equivalent and are "smaller" (farther from one) than 0 or 2.

 */
class WeirdLess
{   public:
	WeirdLess(): count(0) {};
	WeirdLess(const WeirdLess& lt): count(lt.count) {};

	bool operator()(float a, float b){ 
		++count; 
		return fabs(a-1) > fabs(b-1); 
	}

	int comparisons(){ return count; }
	void reset(){ count = 0; }
    private:
	int count;
};
#endif // __WIERD_LESS_H_
