cc.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00037 #ifndef BASE_CC_H
00038 #define BASE_CC_H
00039
00040 #include "fastlib/base/common.h"
00041
00042 #include <algorithm>
00043 #include <limits>
00044
00046 using std::min;
00048 using std::max;
00049
00051 extern const double DBL_NAN;
00053 extern const float FLT_NAN;
00055 extern const double DBL_INF;
00057 extern const float FLT_INF;
00058
00081 #define FORBID_ACCIDENTAL_COPIES(C) \
00082 private: \
00083 C (const C &src); \
00084 const C &operator=(const C &src);
00085
00098 #define ASSIGN_VIA_COPY_CONSTRUCTION(C) \
00099 const C &operator=(const C &src) { \
00100 if (likely(this != &src)) { \
00101 this->~C(); \
00102 new(this) C(src); \
00103 } \
00104 return *this; \
00105 }
00106
00120 #define ASSIGN_VIA_RECURSION_SAFE_COPY_CONSTRUCTION(C) \
00121 const C &operator=(const C &src) { \
00122 if (likely(this != &src)) { \
00123 char buf[sizeof(C)]; \
00124 memcpy(buf, this, sizeof(C)); \
00125 new(this) C(src); \
00126 reinterpret_cast<C *>(buf)->~C(); \
00127 } \
00128 return *this; \
00129 }
00130
00148 #define EXPAND_LESS_THAN(C) \
00149 friend bool operator>(C const &b, C const &a) {return a < b;} \
00150 friend bool operator<=(C const &b, C const &a) {return !(a < b);} \
00151 friend bool operator>=(C const &a, C const &b) {return !(a < b);}
00152
00170 #define EXPAND_GREATER_THAN(C) \
00171 friend bool operator<(C const &b, C const &a) {return a > b;} \
00172 friend bool operator>=(C const &b, C const &a) {return !(a > b);} \
00173 friend bool operator<=(C const &a, C const &b) {return !(a > b);}
00174
00192 #define EXPAND_EQUALS(C) \
00193 friend bool operator!=(C const &a, C const &b) {return !(a == b);}
00194
00220 #define EXPAND_HETERO_LESS_THAN(C, T) \
00221 friend bool operator>(T const &b, C const &a) {return a < b;} \
00222 friend bool operator<=(T const &b, C const &a) {return !(a < b);} \
00223 friend bool operator>=(C const &a, T const &b) {return !(a < b);}
00224
00250 #define EXPAND_HETERO_GREATER_THAN(C, T) \
00251 friend bool operator<(T const &b, C const &a) {return a > b;} \
00252 friend bool operator>=(T const &b, C const &a) {return !(a > b);} \
00253 friend bool operator<=(C const &a, T const &b) {return !(a > b);}
00254
00273 #define EXPAND_HETERO_EQUALS(C, T) \
00274 friend bool operator==(T const &b, C const &a) {return a == b;} \
00275 friend bool operator!=(C const &a, T const &b) {return !(a == b);} \
00276 friend bool operator!=(T const &b, C const &a) {return !(a == b);}
00277
00286 #define FOR_ALL_PRIMITIVES_DO(macro) \
00287 macro(char, "%c") \
00288 macro(short, "%d") \
00289 macro(int, "%d") \
00290 macro(long, "%ld") \
00291 macro(long long, "%lld") \
00292 macro(unsigned char, "%u") \
00293 macro(unsigned short, "%u") \
00294 macro(unsigned int, "%u") \
00295 macro(unsigned long, "%lu") \
00296 macro(unsigned long long, "%llu") \
00297 macro(float, "%g") \
00298 macro(double, "%g") \
00299 macro(long double, "%Lg")
00300
00302 class Empty {};
00303
00304 #endif