diff --git a/alib2std/src/extensions/variant.hpp b/alib2std/src/extensions/variant.hpp index d17a87320340709285062b7ba0539bf7503cc036..dd817f39c7a3f26b59bd578cc1c82cd39e7705b0 100644 --- a/alib2std/src/extensions/variant.hpp +++ b/alib2std/src/extensions/variant.hpp @@ -33,14 +33,30 @@ struct type_id_hash_code { type_id_hash_code ( size_t hash_code ) : m_hash_code ( hash_code ) { } - friend bool operator == ( const type_id_hash_code & first, const type_id_hash_code & second ) { + friend inline bool operator == ( const type_id_hash_code & first, const type_id_hash_code & second ) { return first.m_hash_code == second.m_hash_code; } - friend bool operator != ( const type_id_hash_code & first, const type_id_hash_code & second ) { + friend inline bool operator != ( const type_id_hash_code & first, const type_id_hash_code & second ) { return first.m_hash_code != second.m_hash_code; } + friend inline bool operator < ( const type_id_hash_code & first, const type_id_hash_code & second ) { + return first.m_hash_code < second.m_hash_code; + } + + friend inline bool operator <= ( const type_id_hash_code & first, const type_id_hash_code & second ) { + return first.m_hash_code <= second.m_hash_code; + } + + friend inline bool operator > ( const type_id_hash_code & first, const type_id_hash_code & second ) { + return first.m_hash_code > second.m_hash_code; + } + + friend inline bool operator >= ( const type_id_hash_code & first, const type_id_hash_code & second ) { + return first.m_hash_code >= second.m_hash_code; + } + }; template<typename... Ts> @@ -84,9 +100,6 @@ struct variant_helper<F, Ts...> { } inline static int compareHelper(type_id_hash_code this_t, const void * this_v, type_id_hash_code other_t, const void * other_v) { - if (this_t == typeid(F).hash_code() && other_t != typeid(F).hash_code()) return -1; - if (this_t != typeid(F).hash_code() && other_t == typeid(F).hash_code()) return 1; - if (this_t == typeid(F).hash_code() && other_t == typeid(F).hash_code()) { compare<typename std::decay < F >::type > comp; return comp( *(reinterpret_cast<const F*>(this_v)), *(reinterpret_cast<const F*>(other_v))); @@ -127,9 +140,6 @@ struct variant_helper<void, Ts...> { } inline static int compareHelper(type_id_hash_code this_t, const void * this_v, type_id_hash_code other_t, const void * other_v) { - if (this_t == typeid(void).hash_code() && other_t != typeid(void).hash_code()) return -1; - if (this_t != typeid(void).hash_code() && other_t == typeid(void).hash_code()) return 1; - if (this_t == typeid(void).hash_code() && other_t == typeid(void).hash_code()) return 0; else @@ -238,7 +248,7 @@ public: } bool operator== (const variant<Ts...>& other) const { - return helper_t::compareHelper(this->type_id, &this->data, other.type_id, &other.data) == 0; + return compare ( other ) == 0; } bool operator!= (const variant<Ts...>& other) const { @@ -246,7 +256,7 @@ public: } bool operator< (const variant<Ts...>& other) const { - return helper_t::compareHelper(this->type_id, &this->data, other.type_id, &other.data) < 0; + return compare ( other ) < 0; } bool operator> (const variant<Ts...>& other) const { @@ -262,6 +272,9 @@ public: } int compare(const variant<Ts...>& other) const { + if (this->type_id < other.type_id) return -1; + if (this->type_id > other.type_id) return 1; + return helper_t::compareHelper(this->type_id, &this->data, other.type_id, &other.data); }