13 #include <boost/function.hpp>
15 #define DISALLOW_COPY_AND_ASSIGN(_Class) \
16 _Class(const _Class &); \
17 _Class& operator=(const _Class &)
21 #define CHECK_INVARIANT(Cond) \
24 LOG(WARN, "Invariant failed: " ## Cond); \
29 #define CHECK_INVARIANT(Cond) \
35 template <
typename IntType>
37 return (value & (1 << bit)) != 0;
40 template <
typename IntType>
41 void SetBit(IntType &value,
size_t bit) {
45 template <
typename IntType>
59 #define TOKENPASTE(x, y) x ## y
60 #define TOKENPASTE2(x, y) TOKENPASTE(x, y)
61 #define MODULE_INITIALIZER(Func) \
62 static ModuleInitializer TOKENPASTE2(init_, __LINE__)(Func);
64 #define BOOL_KEY_COMPARE(x, y) \
66 if ((x) < (y)) return true; \
67 if ((y) < (x)) return false; \
70 #define KEY_COMPARE(x, y) \
72 if ((x) < (y)) return -1; \
73 if ((y) < (x)) return 1; \
77 template <
class InputIterator,
class CompareOp>
79 InputIterator first2, InputIterator last2,
81 InputIterator iter1 = first1;
82 InputIterator iter2 = first2;
83 while (iter1 != last1 && iter2 != last2) {
84 int result = op(*iter1, *iter2);
100 template <
typename Container>
102 typename Container::iterator next;
103 for (
typename Container::iterator iter = container->begin();
104 iter != container->end(); iter = next) {
113 template <
typename Container>
115 typename Container::iterator next;
116 for (
typename Container::iterator iter = container->begin();
117 iter != container->end(); iter = next) {
126 template <
typename Collection,
typename T>
128 return col.find(key) != col.end();
131 template <
typename T>
165 template <
class KeyType,
template <
class>
class SmartPointer>
168 const SmartPointer<KeyType> rhs)
const {
169 KeyType *left = lhs.get();
170 KeyType *right = rhs.get();
171 return (*left).IsLess(*right);
void STLDeleteValues(Container *container)
ModuleInitializer(boost::function< void(void)> func)
bool STLKeyExists(const Collection &col, const T &key)
custom_ptr(boost::function< void(T *)> deleter, T *ptr=0)
void SetBit(IntType &value, size_t bit)
void STLDeleteElements(Container *container)
boost::function< void(T *)> deleter_
int STLSortedCompare(InputIterator first1, InputIterator last1, InputIterator first2, InputIterator last2, CompareOp op)
bool operator()(const SmartPointer< KeyType > lhs, const SmartPointer< KeyType > rhs) const
void ClearBit(IntType &value, size_t bit)
bool BitIsSet(IntType value, size_t bit)