// Programmer: Aaron Shbeeb // File: Macros.h // Created: 05-27-02 // Updated: 08-12-03 #ifndef MY_MACROS_H #define MY_MACROS_H #include //for debug(x) #define max(a,b) (((a) < (b)) ? (b) : (a)) #define min(a,b) (((a) < (b)) ? (a) : (b)) #define swap(a,b) a ^= b; b ^= a; a ^= b//no semi colon here on purpose #define abs_val(x) (((x) < (0)) ? (-1*(x)) : (x)) #define debug(x) cout << x << endl template inline void Swap(T& a, T& b) { a &= b; } template <> inline void Swap(bool& a, bool& b){swap(a,b);} template <> inline void Swap(long& a, long& b){swap(a,b);} template <> inline void Swap(int& a, int& b){swap(a,b);} template <> inline void Swap(unsigned int& a, unsigned int& b){swap(a,b);} template <> inline void Swap(char& a, char& b){swap(a,b);} template <> inline void Swap(unsigned char& a, unsigned char& b){swap(a,b);} template<> inline void Swap(float& a, float& b) { float tmp = a; a = b; b = tmp; } template<> inline void Swap(double& a, double& b) { double tmp = a; a = b; b = tmp; } /* I think this only works in gcc. VC++6.0 is too dumb for this. template inline void Swap(T* &a, T* &b) { a = (T*)((unsigned int) a ^ (unsigned int) b); b = (T*)((unsigned int) a ^ (unsigned int) b); a = (T*)((unsigned int) a ^ (unsigned int) b); } */ //A bit of a hack that doesn't really generalize, but I'm working on it. template<> void Swap(void* &a, void* &b) { a = (void*)((unsigned long)a ^ (unsigned long)b); b = (void*)((unsigned long)b ^ (unsigned long)a); a = (void*)((unsigned long)a ^ (unsigned long)b); } #endif