From 858f7533e6d88dbc18934a60d55e99b397d014cd Mon Sep 17 00:00:00 2001 From: rexy712 Date: Tue, 19 Jul 2022 16:43:19 -0700 Subject: [PATCH] Make hasallocator take advantage of empty base optimization for simpler code --- include/rexy/detail/hasallocator.hpp | 40 ++++------------------------ 1 file changed, 5 insertions(+), 35 deletions(-) diff --git a/include/rexy/detail/hasallocator.hpp b/include/rexy/detail/hasallocator.hpp index 9182496..abd761b 100644 --- a/include/rexy/detail/hasallocator.hpp +++ b/include/rexy/detail/hasallocator.hpp @@ -26,47 +26,17 @@ namespace rexy::detail{ - template> - struct hasallocator - { - Alloc m_alloc; - - REXY_CPP20_CONSTEXPR auto allocate(typename Alloc::size_type bytes)noexcept(is_nothrow_allocator_v){ - return m_alloc.allocate(bytes); - } - REXY_CPP20_CONSTEXPR void deallocate(typename Alloc::pointer p, typename Alloc::size_type bytes)noexcept(is_nothrow_allocator_v){ - m_alloc.deallocate(p, bytes); - } - - constexpr Alloc& allocator(void){ - return m_alloc; - } - constexpr const Alloc& allocator(void)const{ - return m_alloc; - } - }; -#if __has_cpp_attribute(no_unique_address) template - struct hasallocator - { - [[no_unique_address]] - Alloc m_alloc; - - REXY_CPP20_CONSTEXPR auto allocate(typename Alloc::size_type bytes)noexcept(is_nothrow_allocator_v){ - return m_alloc.allocate(bytes); - } - REXY_CPP20_CONSTEXPR void deallocate(typename Alloc::pointer p, typename Alloc::size_type bytes)noexcept(is_nothrow_allocator_v){ - m_alloc.deallocate(p, bytes); - } - + struct hasallocator : public Alloc{ + using Alloc::Alloc; + using Alloc::operator=; constexpr Alloc& allocator(void){ - return m_alloc; + return *this; } constexpr const Alloc& allocator(void)const{ - return m_alloc; + return *this; } }; -#endif //no_unique_address } #endif