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 
15 #include <boost/functional/hash/hash.hpp>
16 
17 namespace boost{
18 namespace intrusive{
19 
20 struct int_holder
21 {
int_holderboost::intrusive::int_holder22    explicit int_holder(int value = 0)
23       : int_(value)
24    {}
25 
operator =boost::intrusive::int_holder26    int_holder &operator=(int value)
27    {  int_ = value;  return *this;  }
28 
int_valueboost::intrusive::int_holder29    int int_value() const
30    {  return int_;  }
31 
operator ==(const int_holder & l,const int_holder & r)32    friend bool operator==(const int_holder &l, const int_holder &r)
33    {  return l.int_ == r.int_;  }
34 
operator !=(const int_holder & l,const int_holder & r)35    friend bool operator!=(const int_holder &l, const int_holder &r)
36    {  return l.int_ != r.int_;  }
37 
operator <(const int_holder & l,const int_holder & r)38    friend bool operator<(const int_holder &l, const int_holder &r)
39    {  return l.int_ < r.int_;  }
40 
operator >(const int_holder & l,const int_holder & r)41    friend bool operator>(const int_holder &l, const int_holder &r)
42    {  return l.int_ > r.int_;  }
43 
operator <=(const int_holder & l,const int_holder & r)44    friend bool operator<=(const int_holder &l, const int_holder &r)
45    {  return l.int_ <= r.int_;  }
46 
operator >=(const int_holder & l,const int_holder & r)47    friend bool operator>=(const int_holder &l, const int_holder &r)
48    {  return l.int_ >= r.int_;  }
49 
50 ///
operator ==(int l,const int_holder & r)51    friend bool operator==(int l, const int_holder &r)
52    {  return l == r.int_;  }
53 
operator !=(int l,const int_holder & r)54    friend bool operator!=(int l, const int_holder &r)
55    {  return l != r.int_;  }
56 
operator <(int l,const int_holder & r)57    friend bool operator<(int l, const int_holder &r)
58    {  return l < r.int_;  }
59 
operator >(int l,const int_holder & r)60    friend bool operator>(int l, const int_holder &r)
61    {  return l > r.int_;  }
62 
operator <=(int l,const int_holder & r)63    friend bool operator<=(int l, const int_holder &r)
64    {  return l <= r.int_;  }
65 
operator >=(int l,const int_holder & r)66    friend bool operator>=(int l, const int_holder &r)
67    {  return l >= r.int_;  }
68 
operator <boost::intrusive::int_holder69    bool operator< (int i) const
70    {  return int_ < i;   }
71 
operator >boost::intrusive::int_holder72    bool operator> (int i) const
73    {  return int_ > i;   }
74 
operator <=boost::intrusive::int_holder75    bool operator<= (int i) const
76    {  return int_ <= i;   }
77 
operator >=boost::intrusive::int_holder78    bool operator>= (int i) const
79    {  return int_ >= i;   }
80 
operator ==boost::intrusive::int_holder81    bool operator== (int i) const
82    {  return int_ == i;   }
83 
operator !=boost::intrusive::int_holder84    bool operator!= (int i) const
85    {  return int_ != i;   }
86 
hash_value(const int_holder & t)87    friend std::size_t hash_value(const int_holder &t)
88    {
89       boost::hash<int> hasher;
90       return hasher((&t)->int_value());
91    }
92 
93    int int_;
94 };
95 
96 template<class ValueType>
97 struct int_holder_key_of_value
98 {
99    typedef int_holder type;
100 
operator ()boost::intrusive::int_holder_key_of_value101    type operator()(const ValueType &tv) const
102    {  return tv.get_int_holder();  }
103 };
104 
105 template<class ValueType>
106 struct int_priority_of_value
107 {
108    typedef int type;
109 
operator ()boost::intrusive::int_priority_of_value110    type operator()(const ValueType &tv) const
111    {  return tv.int_value();  }
112 };
113 
114 }  //namespace boost{
115 }  //namespace intrusive{
116 
117 #endif   //BOOST_INTRUSIVE_DETAIL_INT_HOLDER_HPP
118