Guest User

Untitled

a guest
Mar 13th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. #ifndef __INC_METIN_II_STL_H__
  2. #define __INC_METIN_II_STL_H__
  3.  
  4. #include <vector>
  5. #include <string>
  6. #include <map>
  7. #include <list>
  8. #include <functional>
  9. #include <stack>
  10. #include <set>
  11.  
  12. #ifndef itertype
  13. #define itertype(v) __typeof((v).begin())
  14. #endif
  15.  
  16. inline void stl_lowers(std::string& rstRet)
  17. {
  18. for (size_t i = 0; i < rstRet.length(); ++i)
  19. rstRet[i] = tolower(rstRet[i]);
  20. }
  21.  
  22. struct stringhash
  23. {
  24. size_t operator () (const std::string & str) const
  25. {
  26. const unsigned char * s = (const unsigned char*) str.c_str();
  27. const unsigned char * end = s + str.size();
  28. size_t h = 0;
  29.  
  30. while (s < end)
  31. {
  32. h *= 16777619;
  33. h ^= *(s++);
  34. }
  35.  
  36. return h;
  37. }
  38. };
  39.  
  40. // code from tr1/functional_hash.h
  41. template<typename T>
  42. struct hash;
  43.  
  44. template<typename _Tp>
  45. struct hash<_Tp*>
  46. : public std::unary_function<_Tp*, std::size_t>
  47. {
  48. std::size_t
  49. operator()(_Tp* __p) const
  50. { return reinterpret_cast<std::size_t>(__p); }
  51. };
  52.  
  53. namespace std
  54. {
  55. template <class container, class Pred>
  56. void erase_if (container & a, typename container::iterator first, typename container::iterator past, Pred pred)
  57. {
  58. while (first != past)
  59. if (pred(*first))
  60. a.erase(first++);
  61. else
  62. ++first;
  63. }
  64.  
  65. template <class container>
  66. void wipe(container & a)
  67. {
  68. typename container::iterator first, past;
  69.  
  70. first = a.begin();
  71. past = a.end();
  72.  
  73. while (first != past)
  74. delete *(first++);
  75.  
  76. a.clear();
  77. }
  78.  
  79. template <class container>
  80. void wipe_second(container & a)
  81. {
  82. typename container::iterator first, past;
  83.  
  84. first = a.begin();
  85. past = a.end();
  86.  
  87. while (first != past)
  88. {
  89. delete first->second;
  90. ++first;
  91. }
  92.  
  93. a.clear();
  94. }
  95.  
  96. template <typename T> T MIN(T a, T b)
  97. {
  98. return a < b ? a : b;
  99. }
  100.  
  101. template <typename T> T MAX(T a, T b)
  102. {
  103. return a > b ? a : b;
  104. }
  105.  
  106. template <typename T> T MINMAX(T min, T value, T max)
  107. {
  108. T tv;
  109.  
  110. tv = (min > value ? min : value);
  111. return (max < tv) ? max : tv;
  112. }
  113.  
  114. template <class _Ty>
  115. class void_mem_fun_t : public unary_function<_Ty *, void>
  116. {
  117. public:
  118. explicit void_mem_fun_t(void (_Ty::*_Pm)()) : _Ptr(_Pm)
  119. {
  120. }
  121.  
  122. void operator()(_Ty* p) const
  123. {
  124. ((p->*_Ptr)());
  125. }
  126.  
  127. private:
  128. void (_Ty::*_Ptr)();
  129. };
  130.  
  131. template<class _Ty> inline
  132. void_mem_fun_t<_Ty> void_mem_fun(void (_Ty::*_Pm)())
  133. { return (void_mem_fun_t<_Ty>(_Pm)); }
  134.  
  135. template<class _Ty>
  136. class void_mem_fun_ref_t : public unary_function<_Ty, void>
  137. {
  138. public:
  139. explicit void_mem_fun_ref_t(void (_Ty::*_Pm)()) : _Ptr(_Pm) {}
  140. void operator()(_Ty& x) const
  141. { return ((x.*_Ptr)()); }
  142. private:
  143. void (_Ty::*_Ptr)();
  144. };
  145.  
  146. template<class _Ty> inline
  147. void_mem_fun_ref_t<_Ty> void_mem_fun_ref(void (_Ty::*_Pm)())
  148. { return (void_mem_fun_ref_t< _Ty>(_Pm)); }
  149. };
  150.  
  151. #endif
Add Comment
Please, Sign In to add comment