Skip to content

Commit

Permalink
Add has_nothrow_equal and has_nothrow_not_equal
Browse files Browse the repository at this point in the history
  • Loading branch information
KredeGC committed Jun 23, 2023
1 parent 71a6784 commit 8c33eb9
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions include/ktl/allocators/fallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ namespace ktl
fallback& operator=(fallback&&) = default;

bool operator==(const fallback& rhs) const
noexcept(noexcept(m_Primary == rhs.m_Primary) && noexcept(m_Fallback == rhs.m_Fallback))
noexcept(detail::has_nothrow_equal_v<P> && detail::has_nothrow_equal_v<F>)
{
return m_Primary == rhs.m_Primary && m_Fallback == rhs.m_Fallback;
}

bool operator!=(const fallback& rhs) const
noexcept(noexcept(m_Primary != rhs.m_Primary) && noexcept(m_Fallback != rhs.m_Fallback))
noexcept(detail::has_nothrow_not_equal_v<P>&& detail::has_nothrow_not_equal_v<F>)
{
return m_Primary != rhs.m_Primary || m_Fallback != rhs.m_Fallback;
}
Expand Down
4 changes: 2 additions & 2 deletions include/ktl/allocators/freelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ namespace ktl
}

bool operator==(const freelist& rhs) const
noexcept(noexcept(m_Alloc == rhs.m_Alloc))
noexcept(detail::has_nothrow_equal_v<Alloc>)
{
return m_Alloc == rhs.m_Alloc && m_Free == rhs.m_Free;
}

bool operator!=(const freelist& rhs) const
noexcept(noexcept(m_Alloc != rhs.m_Alloc))
noexcept(detail::has_nothrow_not_equal_v<Alloc>)
{
return m_Alloc != rhs.m_Alloc || m_Free != rhs.m_Free;
}
Expand Down
4 changes: 2 additions & 2 deletions include/ktl/allocators/overflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ namespace ktl
overflow& operator=(overflow&&) = default;

bool operator==(const overflow& rhs) const
noexcept(noexcept(m_Alloc == rhs.m_Alloc))
noexcept(detail::has_nothrow_equal_v<Alloc>)
{
return m_Alloc == rhs.m_Alloc;
}

bool operator!=(const overflow& rhs) const
noexcept(noexcept(m_Alloc != rhs.m_Alloc))
noexcept(detail::has_nothrow_not_equal_v<Alloc>)
{
return m_Alloc != rhs.m_Alloc;
}
Expand Down
4 changes: 2 additions & 2 deletions include/ktl/allocators/segragator.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ namespace ktl
segragator& operator=(segragator&&) = default;

bool operator==(const segragator& rhs) const
noexcept(noexcept(m_Primary == rhs.m_Primary) && noexcept(m_Fallback == rhs.m_Fallback))
noexcept(detail::has_nothrow_equal_v<P> && detail::has_nothrow_equal_v<F>)
{
return m_Primary == rhs.m_Primary && m_Fallback == rhs.m_Fallback;
}

bool operator!=(const segragator& rhs) const
noexcept(noexcept(m_Primary != rhs.m_Primary) && noexcept(m_Fallback != rhs.m_Fallback))
noexcept(detail::has_nothrow_not_equal_v<P>&& detail::has_nothrow_not_equal_v<F>)
{
return m_Primary != rhs.m_Primary || m_Fallback != rhs.m_Fallback;
}
Expand Down
4 changes: 2 additions & 2 deletions include/ktl/allocators/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ namespace ktl
}

bool operator==(const shared& rhs) const
noexcept(noexcept(m_Block->Allocator == rhs.m_Block->Allocator))
noexcept(detail::has_nothrow_equal_v<Alloc>)
{
return m_Block == rhs.m_Block && m_Block->Allocator == rhs.m_Block->Allocator;
}

bool operator!=(const shared& rhs) const
noexcept(noexcept(m_Block->Allocator != rhs.m_Block->Allocator))
noexcept(detail::has_nothrow_not_equal_v<Alloc>)
{
return m_Block != rhs.m_Block || m_Block->Allocator != rhs.m_Block->Allocator;
}
Expand Down
4 changes: 2 additions & 2 deletions include/ktl/allocators/threaded.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ namespace ktl
}

bool operator==(const threaded& rhs) const
noexcept(noexcept(m_Block->Allocator == rhs.m_Block->Allocator))
noexcept(detail::has_nothrow_equal_v<Alloc>)
{
return m_Block == rhs.m_Block && m_Block->Allocator == rhs.m_Block->Allocator;
}

bool operator!=(const threaded& rhs) const
noexcept(noexcept(m_Block->Allocator != rhs.m_Block->Allocator))
noexcept(detail::has_nothrow_not_equal_v<Alloc>)
{
return m_Block != rhs.m_Block || m_Block->Allocator != rhs.m_Block->Allocator;
}
Expand Down
4 changes: 2 additions & 2 deletions include/ktl/allocators/type_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ namespace ktl

template<typename T, typename U, typename Alloc>
bool operator==(const type_allocator<T, Alloc>& lhs, const type_allocator<U, Alloc>& rhs)
noexcept(noexcept(lhs.get_allocator() == rhs.get_allocator()))
noexcept(detail::has_nothrow_equal_v<Alloc>)
{
return lhs.get_allocator() == rhs.get_allocator();
}

template<typename T, typename U, typename Alloc>
bool operator!=(const type_allocator<T, Alloc>& lhs, const type_allocator<U, Alloc>& rhs)
noexcept(noexcept(lhs.get_allocator() != rhs.get_allocator()))
noexcept(detail::has_nothrow_not_equal_v<Alloc>)
{
return lhs.get_allocator() != rhs.get_allocator();
}
Expand Down
8 changes: 8 additions & 0 deletions include/ktl/utility/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ namespace ktl::detail
template<typename Alloc>
constexpr bool has_nothrow_deallocate_v = noexcept(std::declval<Alloc&>().deallocate(std::declval<void*>(), std::declval<size_t>()));

// has T& == T& noexcept
template<typename T>
constexpr bool has_nothrow_equal_v = noexcept(std::declval<T&>() == std::declval<T&>());

// has T& == T& noexcept
template<typename T>
constexpr bool has_nothrow_not_equal_v = noexcept(std::declval<T&>() == std::declval<T&>());

// has construct(T*, Args&&...) noexcept
template<typename Void, typename... Types>
struct has_nothrow_construct : std::false_type {};
Expand Down

0 comments on commit 8c33eb9

Please sign in to comment.