diff --git a/include/ktl/allocators/freelist.h b/include/ktl/allocators/freelist.h index b6020ce..e4d3c08 100644 --- a/include/ktl/allocators/freelist.h +++ b/include/ktl/allocators/freelist.h @@ -37,7 +37,9 @@ namespace ktl }; public: - freelist() noexcept : + template + freelist() + noexcept(std::is_nothrow_default_constructible_v) : m_Alloc(), m_Free(nullptr) {} @@ -48,13 +50,14 @@ namespace ktl typename = std::enable_if_t< detail::can_construct_v>> explicit freelist(Args&&... args) - noexcept(noexcept(Alloc(std::declval() ...))) : + noexcept(std::is_nothrow_constructible_v) : m_Alloc(std::forward(args)...), m_Free(nullptr) {} freelist(const freelist&) = delete; - freelist(freelist&& other) noexcept : + freelist(freelist&& other) + noexcept(std::is_nothrow_move_constructible) : m_Alloc(std::move(other.m_Alloc)), m_Free(other.m_Free) { @@ -71,7 +74,8 @@ namespace ktl freelist& operator=(const freelist&) = delete; - freelist& operator=(freelist&& rhs) noexcept + freelist& operator=(freelist&& rhs) + noexcept(std::is_nothrow_move_constructible) { release(); @@ -107,7 +111,7 @@ namespace ktl * @return A location in memory that is at least @p n bytes big or nullptr if it could not be allocated */ void* allocate(size_type n) - noexcept(noexcept(m_Alloc.allocate(Max))) + noexcept(detail::has_nothrow_allocate_v) { if (n > Min && n <= Max) { @@ -154,7 +158,7 @@ namespace ktl template typename std::enable_if, void>::type construct(T* p, Args&&... args) - noexcept(detail::has_noexcept_construct_v) + noexcept(detail::has_nothrow_construct_v) { m_Alloc.construct(p, std::forward(args)...); } @@ -167,7 +171,7 @@ namespace ktl template typename std::enable_if, void>::type destroy(T* p) - noexcept(detail::has_noexcept_destroy_v) + noexcept(detail::has_nothrow_destroy_v) { m_Alloc.destroy(p); } @@ -222,7 +226,7 @@ namespace ktl private: void release() - noexcept(noexcept(m_Alloc.deallocate(m_Free, Max))) + noexcept(detail::has_nothrow_deallocate_v) { link* next = m_Free; while (next) diff --git a/include/ktl/allocators/overflow.h b/include/ktl/allocators/overflow.h index a405c4e..cabfb70 100644 --- a/include/ktl/allocators/overflow.h +++ b/include/ktl/allocators/overflow.h @@ -44,7 +44,7 @@ namespace ktl */ template>> + std::is_constructible_v>> explicit overflow(Stream& stream, Args&&... args) noexcept(std::is_nothrow_constructible_v) : m_Stream(stream), @@ -102,7 +102,7 @@ namespace ktl * @return A location in memory that is at least @p n bytes big or nullptr if it could not be allocated */ void* allocate(size_type n) - noexcept(noexcept(m_Alloc.allocate(n))) + noexcept(detail::has_nothrow_allocate_v) { m_Allocs += n; @@ -124,7 +124,7 @@ namespace ktl * @param n The size that was initially allocated */ void deallocate(void* p, size_type n) - noexcept(noexcept(m_Alloc.deallocate(p, n))) + noexcept(detail::has_nothrow_deallocate_v) { KTL_ASSERT(p != nullptr); diff --git a/include/ktl/allocators/segragator.h b/include/ktl/allocators/segragator.h index 33c91c1..bf6a1c6 100644 --- a/include/ktl/allocators/segragator.h +++ b/include/ktl/allocators/segragator.h @@ -26,10 +26,7 @@ namespace ktl public: typedef typename detail::get_size_type_t

size_type; - segragator() - noexcept(std::is_nothrow_default_constructible_v

&& std::is_nothrow_default_constructible_v) : - m_Primary(), - m_Fallback() {} + segragator() = default; /** * @brief Constructor for forwarding a single argument to the primary allocator @@ -98,7 +95,7 @@ namespace ktl #pragma region Allocation void* allocate(size_t n) - noexcept(noexcept(m_Primary.allocate(n)) && noexcept(m_Fallback.allocate(n))) + noexcept(detail::has_nothrow_allocate_v

&& detail::has_nothrow_allocate_v) { if (n <= Threshold) return m_Primary.allocate(n); @@ -107,7 +104,7 @@ namespace ktl } void deallocate(void* p, size_t n) - noexcept(noexcept(m_Primary.deallocate(p, n)) && noexcept(m_Fallback.deallocate(p, n))) + noexcept(detail::has_nothrow_deallocate_v

&& detail::has_nothrow_deallocate_v) { if (n <= Threshold) return m_Primary.deallocate(p, n); @@ -182,7 +179,7 @@ namespace ktl template typename std::enable_if && detail::has_max_size_v, size_type>::type max_size() const - noexcept(detail::has_nothrow_max_size_v

&& detail::has_nothrow_max_size_v) + noexcept(detail::has_nothrow_max_size_v && detail::has_nothrow_max_size_v) { return (std::max)(m_Primary.max_size(), m_Fallback.max_size()); } @@ -190,7 +187,7 @@ namespace ktl template typename std::enable_if && detail::has_owns_v, bool>::type owns(void* p) const - noexcept(detail::has_nothrow_owns_v

&& detail::has_nothrow_owns_v) + noexcept(detail::has_nothrow_owns_v && detail::has_nothrow_owns_v) { if (m_Primary.owns(p)) return true; diff --git a/include/ktl/allocators/shared.h b/include/ktl/allocators/shared.h index fdab2eb..d1901a8 100644 --- a/include/ktl/allocators/shared.h +++ b/include/ktl/allocators/shared.h @@ -26,7 +26,7 @@ namespace ktl typename = std::enable_if_t< detail::can_construct_v>> block(Args&&... alloc) - noexcept(noexcept(Alloc(std::declval()...))) : + noexcept(std::is_nothrow_constructible_v) : Allocator(std::forward(alloc)...), UseCount(1) {} }; @@ -34,8 +34,9 @@ namespace ktl public: typedef typename detail::get_size_type_t size_type; + template shared() - noexcept(noexcept(block())) : + noexcept(std::is_nothrow_default_constructible_v) : m_Block(detail::aligned_new(detail::ALIGNMENT)) {} /** @@ -45,7 +46,7 @@ namespace ktl typename = std::enable_if_t< detail::can_construct_v>> explicit shared(Args&&... alloc) - noexcept(noexcept(block(std::declval()...))) : + noexcept(std::is_nothrow_constructible_v) : m_Block(detail::aligned_new(detail::ALIGNMENT, std::forward(alloc)...)) {} shared(const shared& other) noexcept : @@ -103,13 +104,13 @@ namespace ktl #pragma region Allocation void* allocate(size_t n) - noexcept(noexcept(m_Block->Allocator.allocate(n))) + noexcept(detail::has_nothrow_allocate_v) { return m_Block->Allocator.allocate(n); } void deallocate(void* p, size_t n) - noexcept(noexcept(m_Block->Allocator.deallocate(p, n))) + noexcept(detail::has_nothrow_deallocate_v) { m_Block->Allocator.deallocate(p, n); } @@ -119,7 +120,7 @@ namespace ktl template typename std::enable_if, void>::type construct(T* p, Args&&... args) - noexcept(detail::has_noexcept_construct_v) + noexcept(detail::has_nothrow_construct_v) { m_Block->Allocator.construct(p, std::forward(args)...); } @@ -127,7 +128,7 @@ namespace ktl template typename std::enable_if, void>::type destroy(T* p) - noexcept(detail::has_noexcept_destroy_v) + noexcept(detail::has_nothrow_destroy_v) { m_Block->Allocator.destroy(p); } @@ -137,7 +138,7 @@ namespace ktl template typename std::enable_if, size_type>::type max_size() const - noexcept(noexcept(std::declval().max_size())) + noexcept(detail::has_nothrow_max_size_v) { return m_Block->Allocator.max_size(); } @@ -145,7 +146,7 @@ namespace ktl template typename std::enable_if, bool>::type owns(void* p) const - noexcept(noexcept(std::declval().owns(p))) + noexcept(detail::has_nothrow_owns_v) { return m_Block->Allocator.owns(p); } @@ -170,7 +171,7 @@ namespace ktl } void decrement() - noexcept(noexcept(detail::aligned_delete(m_Block))) + noexcept(std::is_nothrow_destructible_v) { if (!m_Block) return; diff --git a/include/ktl/allocators/threaded.h b/include/ktl/allocators/threaded.h index 13f38c4..967e518 100644 --- a/include/ktl/allocators/threaded.h +++ b/include/ktl/allocators/threaded.h @@ -29,7 +29,7 @@ namespace ktl typename = std::enable_if_t< detail::can_construct_v>> block(Args&&... alloc) - noexcept(noexcept(Alloc(std::declval()...))) : + noexcept(std::is_nothrow_constructible_v) : Allocator(std::forward(alloc)...), UseCount(1), Lock() {} @@ -38,8 +38,9 @@ namespace ktl public: typedef typename detail::get_size_type_t size_type; + template threaded() - noexcept(noexcept(block())) : + noexcept(std::is_nothrow_default_constructible_v) : m_Block(detail::aligned_new(detail::ALIGNMENT)) {} /** @@ -49,7 +50,7 @@ namespace ktl typename = std::enable_if_t< detail::can_construct_v>> explicit threaded(Args&&... alloc) - noexcept(noexcept(block(std::declval()...))) : + noexcept(std::is_nothrow_constructible_v) : m_Block(detail::aligned_new(detail::ALIGNMENT, std::forward(alloc)...)) {} threaded(const threaded& other) noexcept : @@ -145,7 +146,7 @@ namespace ktl template typename std::enable_if, size_type>::type max_size() const - noexcept(noexcept(m_Block->Allocator.max_size())) + noexcept(detail::has_nothrow_max_size_v) { return m_Block->Allocator.max_size(); } @@ -153,7 +154,7 @@ namespace ktl template typename std::enable_if, bool>::type owns(void* p) const - noexcept(noexcept(m_Block->Allocator.owns(p))) + noexcept(detail::has_nothrow_owns_v) { return m_Block->Allocator.owns(p); } @@ -178,7 +179,7 @@ namespace ktl } void decrement() - noexcept(noexcept(detail::aligned_delete(m_Block))) + noexcept(std::is_nothrow_destructible_v) { if (!m_Block) return;