Add overloads of comparison operators to allow comparison of safe/uint128 and native integer classes

This commit is contained in:
Eric Frias 2015-05-19 10:02:37 -04:00
parent 71cca4559c
commit 3508e0c034
3 changed files with 60 additions and 1 deletions

View file

@ -258,6 +258,11 @@ target_include_directories(fc
#target_link_libraries( fc PUBLIC easylzma_static scrypt udt ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library})
target_link_libraries( fc PUBLIC easylzma_static udt ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${readline_libraries})
if(MSVC)
set_source_files_properties( src/network/http/websocket.cpp PROPERTIES COMPILE_FLAGS "/bigobj" )
endif(MSVC)
IF(NOT Boost_UNIT_TEST_FRAMEWORK_LIBRARY MATCHES "\\.(a|lib)$")
IF(WIN32)
add_definitions(/DBOOST_TEST_DYN_LINK)

View file

@ -64,26 +64,74 @@ namespace fc {
{
return a.value == b.value;
}
friend bool operator == ( const safe& a, const T& b )
{
return a.value == b;
}
friend bool operator == ( const T& a, const safe& b )
{
return a == b.value;
}
friend bool operator != ( const safe& a, const safe& b )
{
return a.value != b.value;
}
friend bool operator != ( const safe& a, const T& b )
{
return a.value != b;
}
friend bool operator != ( const T& a, const safe& b )
{
return a != b.value;
}
friend bool operator < ( const safe& a, const safe& b )
{
return a.value < b.value;
}
friend bool operator < ( const safe& a, const T& b )
{
return a.value < b;
}
friend bool operator < ( const T& a, const safe& b )
{
return a < b.value;
}
friend bool operator > ( const safe& a, const safe& b )
{
return a.value > b.value;
}
friend bool operator > ( const safe& a, const T& b )
{
return a.value > b;
}
friend bool operator > ( const T& a, const safe& b )
{
return a > b.value;
}
friend bool operator >= ( const safe& a, const safe& b )
{
return a.value >= b.value;
}
friend bool operator >= ( const safe& a, const T& b )
{
return a.value >= b;
}
friend bool operator >= ( const T& a, const safe& b )
{
return a >= b.value;
}
friend bool operator <= ( const safe& a, const safe& b )
{
return a.value <= b.value;
}
friend bool operator <= ( const safe& a, const T& b )
{
return a.value <= b;
}
friend bool operator <= ( const T& a, const safe& b )
{
return a <= b.value;
}
T value = 0;
};

View file

@ -39,6 +39,7 @@ namespace fc
bool operator == ( const uint128& o )const{ return hi == o.hi && lo == o.lo; }
bool operator != ( const uint128& o )const{ return hi != o.hi || lo != o.lo; }
bool operator < ( const uint128& o )const { return (hi == o.hi) ? lo < o.lo : hi < o.hi; }
bool operator < ( const int64_t& o )const { return *this < uint128(o); }
bool operator !()const { return !(hi !=0 || lo != 0); }
uint128 operator -()const { return ++uint128( ~hi, ~lo ); }
uint128 operator ~()const { return uint128( ~hi, ~lo ); }
@ -72,10 +73,15 @@ namespace fc
friend uint128 operator << ( const uint128& l, const uint128& r ) { return uint128(l)<<=r; }
friend uint128 operator >> ( const uint128& l, const uint128& r ) { return uint128(l)>>=r; }
friend bool operator > ( const uint128& l, const uint128& r ) { return r < l; }
friend bool operator > ( const uint128& l, const int64_t& r ) { return uint128(r) < l; }
friend bool operator > ( const int64_t& l, const uint128& r ) { return r < uint128(l); }
friend bool operator >= ( const uint128& l, const uint128& r ) { return l == r || l > r; }
friend bool operator >= ( const uint128& l, const int64_t& r ) { return l >= uint128(r); }
friend bool operator >= ( const int64_t& l, const uint128& r ) { return uint128(l) >= r; }
friend bool operator <= ( const uint128& l, const uint128& r ) { return l == r || l < r; }
friend bool operator <= ( const uint128& l, const int64_t& r ) { return l <= uint128(r); }
friend bool operator <= ( const int64_t& l, const uint128& r ) { return uint128(l) <= r; }
friend std::size_t hash_value( const uint128& v ) { return city_hash_size_t((const char*)&v, sizeof(v)); }