Add a comparison operators for signed_int, correct the ones for unsigned_int

This commit is contained in:
Eric Frias 2014-06-26 15:51:35 -04:00
parent 560b107e58
commit c925ceb232

View file

@ -19,12 +19,21 @@ struct unsigned_int {
uint32_t value;
friend bool operator==( const unsigned_int& i, const uint32_t& v ) { return v == i.value; }
friend bool operator!=( const unsigned_int& i, const uint32_t& v ) { return v != i.value; }
friend bool operator<( const unsigned_int& i, const uint32_t& v ) { return v < i.value; }
friend bool operator>=( const unsigned_int& i, const uint32_t& v ) { return v >= i.value; }
friend bool operator<( const unsigned_int& i, const unsigned_int& v ) { return v < i.value; }
friend bool operator>=( const unsigned_int& i, const unsigned_int& v ) { return v >= i.value; }
friend bool operator==( const unsigned_int& i, const uint32_t& v ) { return i.value == v; }
friend bool operator==( const uint32_t& i, const unsigned_int& v ) { return i == v.value; }
friend bool operator==( const unsigned_int& i, const unsigned_int& v ) { return i.value == v.value; }
friend bool operator!=( const unsigned_int& i, const uint32_t& v ) { return i.value != v; }
friend bool operator!=( const uint32_t& i, const unsigned_int& v ) { return i != v.value; }
friend bool operator!=( const unsigned_int& i, const unsigned_int& v ) { return i.value != v.value; }
friend bool operator<( const unsigned_int& i, const uint32_t& v ) { return i.value < v; }
friend bool operator<( const uint32_t& i, const unsigned_int& v ) { return i < v.value; }
friend bool operator<( const unsigned_int& i, const unsigned_int& v ) { return i.value < v.value; }
friend bool operator>=( const unsigned_int& i, const uint32_t& v ) { return i.value >= v; }
friend bool operator>=( const uint32_t& i, const unsigned_int& v ) { return i >= v.value; }
friend bool operator>=( const unsigned_int& i, const unsigned_int& v ) { return i.value >= v.value; }
};
/**
@ -41,6 +50,22 @@ struct signed_int {
signed_int& operator++(){ ++value; return *this; }
int32_t value;
friend bool operator==( const signed_int& i, const int32_t& v ) { return i.value == v; }
friend bool operator==( const int32_t& i, const signed_int& v ) { return i == v.value; }
friend bool operator==( const signed_int& i, const signed_int& v ) { return i.value == v.value; }
friend bool operator!=( const signed_int& i, const int32_t& v ) { return i.value != v; }
friend bool operator!=( const int32_t& i, const signed_int& v ) { return i != v.value; }
friend bool operator!=( const signed_int& i, const signed_int& v ) { return i.value != v.value; }
friend bool operator<( const signed_int& i, const int32_t& v ) { return i.value < v; }
friend bool operator<( const int32_t& i, const signed_int& v ) { return i < v.value; }
friend bool operator<( const signed_int& i, const signed_int& v ) { return i.value < v.value; }
friend bool operator>=( const signed_int& i, const int32_t& v ) { return i.value >= v; }
friend bool operator>=( const int32_t& i, const signed_int& v ) { return i >= v.value; }
friend bool operator>=( const signed_int& i, const signed_int& v ) { return i.value >= v.value; }
};
class variant;
@ -64,4 +89,13 @@ namespace std
return std::hash<int32_t>()(a.value);
}
};
template<>
struct hash<fc::unsigned_int>
{
public:
size_t operator()(const fc::signed_int &a) const
{
return std::hash<uint32_t>()(a.value);
}
};
}