int_holder.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2015-2015.
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/intrusive for documentation.
  10. //
  11. /////////////////////////////////////////////////////////////////////////////
  12. #ifndef BOOST_INTRUSIVE_DETAIL_INT_HOLDER_HPP
  13. #define BOOST_INTRUSIVE_DETAIL_INT_HOLDER_HPP
  14. #include <boost/functional/hash/hash.hpp>
  15. namespace boost{
  16. namespace intrusive{
  17. struct int_holder
  18. {
  19. explicit int_holder(int value = 0)
  20. : int_(value)
  21. {}
  22. int_holder &operator=(int value)
  23. { int_ = value; return *this; }
  24. int int_value() const
  25. { return int_; }
  26. friend bool operator==(const int_holder &l, const int_holder &r)
  27. { return l.int_ == r.int_; }
  28. friend bool operator!=(const int_holder &l, const int_holder &r)
  29. { return l.int_ != r.int_; }
  30. friend bool operator<(const int_holder &l, const int_holder &r)
  31. { return l.int_ < r.int_; }
  32. friend bool operator>(const int_holder &l, const int_holder &r)
  33. { return l.int_ > r.int_; }
  34. friend bool operator<=(const int_holder &l, const int_holder &r)
  35. { return l.int_ <= r.int_; }
  36. friend bool operator>=(const int_holder &l, const int_holder &r)
  37. { return l.int_ >= r.int_; }
  38. ///
  39. friend bool operator==(int l, const int_holder &r)
  40. { return l == r.int_; }
  41. friend bool operator!=(int l, const int_holder &r)
  42. { return l != r.int_; }
  43. friend bool operator<(int l, const int_holder &r)
  44. { return l < r.int_; }
  45. friend bool operator>(int l, const int_holder &r)
  46. { return l > r.int_; }
  47. friend bool operator<=(int l, const int_holder &r)
  48. { return l <= r.int_; }
  49. friend bool operator>=(int l, const int_holder &r)
  50. { return l >= r.int_; }
  51. bool operator< (int i) const
  52. { return int_ < i; }
  53. bool operator> (int i) const
  54. { return int_ > i; }
  55. bool operator<= (int i) const
  56. { return int_ <= i; }
  57. bool operator>= (int i) const
  58. { return int_ >= i; }
  59. bool operator== (int i) const
  60. { return int_ == i; }
  61. bool operator!= (int i) const
  62. { return int_ != i; }
  63. friend std::size_t hash_value(const int_holder &t)
  64. {
  65. boost::hash<int> hasher;
  66. return hasher((&t)->int_value());
  67. }
  68. int int_;
  69. };
  70. template<class ValueType>
  71. struct int_holder_key_of_value
  72. {
  73. typedef int_holder type;
  74. type operator()(const ValueType &tv) const
  75. { return tv.get_int_holder(); }
  76. };
  77. template<class ValueType>
  78. struct int_priority_of_value
  79. {
  80. typedef int type;
  81. type operator()(const ValueType &tv) const
  82. { return tv.int_value(); }
  83. };
  84. } //namespace boost{
  85. } //namespace intrusive{
  86. #endif //BOOST_INTRUSIVE_DETAIL_INT_HOLDER_HPP