Make hasallocator take advantage of empty base optimization for simpler code
This commit is contained in:
parent
43dc4b6654
commit
858f7533e6
@ -26,47 +26,17 @@
|
||||
|
||||
namespace rexy::detail{
|
||||
|
||||
template<REXY_ALLOCATOR_CONCEPT Alloc, bool EmptyAlloc = std::is_empty_v<Alloc>>
|
||||
struct hasallocator
|
||||
{
|
||||
Alloc m_alloc;
|
||||
|
||||
REXY_CPP20_CONSTEXPR auto allocate(typename Alloc::size_type bytes)noexcept(is_nothrow_allocator_v<Alloc>){
|
||||
return m_alloc.allocate(bytes);
|
||||
}
|
||||
REXY_CPP20_CONSTEXPR void deallocate(typename Alloc::pointer p, typename Alloc::size_type bytes)noexcept(is_nothrow_allocator_v<Alloc>){
|
||||
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<REXY_ALLOCATOR_CONCEPT Alloc>
|
||||
struct hasallocator<Alloc,true>
|
||||
{
|
||||
[[no_unique_address]]
|
||||
Alloc m_alloc;
|
||||
|
||||
REXY_CPP20_CONSTEXPR auto allocate(typename Alloc::size_type bytes)noexcept(is_nothrow_allocator_v<Alloc>){
|
||||
return m_alloc.allocate(bytes);
|
||||
}
|
||||
REXY_CPP20_CONSTEXPR void deallocate(typename Alloc::pointer p, typename Alloc::size_type bytes)noexcept(is_nothrow_allocator_v<Alloc>){
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user