Cytopia  0.3
A city building simulation game
IEquatable.inl.hxx
Go to the documentation of this file.
1 
2 template <typename Type> IEquatable<Type>::IEquatable()
3 {
4  using FunctorType = typename GetMemberType<decltype(&Type::Hash)>::type;
5  static_assert(std::is_same_v<FunctorType, std::size_t() const noexcept>,
6  "You must implement std::size_t Hash() const noexcept and make it accessible to IEquatable");
7 }
8 
9 template <typename Type> constexpr bool IEquatable<Type>::operator!=(const IEquatable<Type> &other) const noexcept
10 {
11  return m_Hash != other.m_Hash;
12 }
13 
14 template <typename Type> bool IEquatable<Type>::operator==(const IEquatable<Type> &other) const noexcept
15 {
17  {
18  return m_Hash == other.m_Hash && Type::Equals(other);
19  }
20  else
21  {
22  return m_Hash == other.m_Hash;
23  }
24 }
25 
26 template <typename Type> void IEquatable<Type>::onHashChanged(std::size_t hash) noexcept { m_Hash = hash; }
27 template <typename Type> void IEquatable<Type>::onHashChanged() noexcept { m_Hash = static_cast<Type &>(*this).Hash(); }
IEquatable::operator!=
constexpr bool operator!=(const IEquatable< Type > &other) const noexcept
Definition: IEquatable.inl.hxx:9
IEquatable::IEquatable
IEquatable()
Create an Equatable type.
Definition: IEquatable.inl.hxx:2
IEquatable::onHashChanged
void onHashChanged() noexcept
Call when the hash has changed.
Definition: IEquatable.inl.hxx:27
GetMemberType
Definition: Meta.hxx:94
IEquatable::operator==
bool operator==(const IEquatable< Type > &other) const noexcept
Definition: IEquatable.inl.hxx:14
is_strong_equatable_type
Is true if a type is strongly equatable.
Definition: IEquatable.hxx:9
IEquatable
Allows Type to be hashable, use operator==, and use operator!=.
Definition: IEquatable.hxx:28