Change buffer to use allocator traits

This commit is contained in:
rexy712 2022-06-29 17:32:02 -07:00
parent d9cba881ac
commit 31327248e0
2 changed files with 10 additions and 12 deletions

View File

@ -52,17 +52,16 @@ namespace rexy{
public:
constexpr buffer(void);
REXY_CPP20_CONSTEXPR buffer(const_pointer data, size_type length)noexcept(noexcept(this->allocate(0)));
REXY_CPP20_CONSTEXPR buffer(const_pointer data, size_type length)noexcept(is_nothrow_allocator_v<Allocator>);
template<class Iter>
REXY_CPP20_CONSTEXPR buffer(const Iter& start, const Iter& last);
REXY_CPP20_CONSTEXPR buffer(size_type cap)noexcept(noexcept(this->allocate(0)));
REXY_CPP20_CONSTEXPR buffer(const buffer& b)noexcept(noexcept(this->allocate(0)));
REXY_CPP20_CONSTEXPR buffer(size_type cap)noexcept(is_nothrow_allocator_v<Allocator>);
REXY_CPP20_CONSTEXPR buffer(const buffer& b)noexcept(is_nothrow_allocator_v<Allocator>);
constexpr buffer(buffer&& b)noexcept;
REXY_CPP20_CONSTEXPR ~buffer(void)noexcept(noexcept(this->deallocate(nullptr, 0)));
REXY_CPP20_CONSTEXPR ~buffer(void)noexcept(is_nothrow_allocator_v<Allocator>);
REXY_CPP20_CONSTEXPR buffer& operator=(const buffer& b)
noexcept(noexcept(this->allocate(0)) &&
noexcept(this->deallocate(nullptr, 0)));
noexcept(is_nothrow_allocator_v<Allocator>);
constexpr buffer& operator=(buffer&& b)noexcept;
constexpr pointer data(void);

View File

@ -27,7 +27,7 @@ namespace rexy{
template<class T, class Allocator>
constexpr buffer<T,Allocator>::buffer(void){}
template<class T, class Allocator>
REXY_CPP20_CONSTEXPR buffer<T,Allocator>::buffer(const_pointer data, size_type length)noexcept(noexcept(this->allocate(0))):
REXY_CPP20_CONSTEXPR buffer<T,Allocator>::buffer(const_pointer data, size_type length)noexcept(is_nothrow_allocator_v<Allocator>):
m_data(this->allocate(sizeof(value_type) * length)),
m_cap(length),
m_size(length)
@ -54,12 +54,12 @@ namespace rexy{
m_size = count;
}
template<class T, class Allocator>
REXY_CPP20_CONSTEXPR buffer<T,Allocator>::buffer(size_type cap)noexcept(noexcept(this->allocate(0))):
REXY_CPP20_CONSTEXPR buffer<T,Allocator>::buffer(size_type cap)noexcept(is_nothrow_allocator_v<Allocator>):
m_data(this->allocate(sizeof(value_type) * cap)),
m_cap(cap),
m_size(0){}
template<class T, class Allocator>
REXY_CPP20_CONSTEXPR buffer<T,Allocator>::buffer(const buffer& b)noexcept(noexcept(this->allocate(0))):
REXY_CPP20_CONSTEXPR buffer<T,Allocator>::buffer(const buffer& b)noexcept(is_nothrow_allocator_v<Allocator>):
m_data(this->allocate(sizeof(value_type) * b.m_cap)),
m_cap(b.m_cap),
m_size(b.m_size)
@ -74,7 +74,7 @@ namespace rexy{
m_cap(b.m_cap),
m_size(b.m_size){}
template<class T, class Allocator>
REXY_CPP20_CONSTEXPR buffer<T,Allocator>::~buffer(void)noexcept(noexcept(this->deallocate(nullptr, 0))){
REXY_CPP20_CONSTEXPR buffer<T,Allocator>::~buffer(void)noexcept(is_nothrow_allocator_v<Allocator>){
for(size_type i = 0;i < m_size;++i){
m_data[i].~T();
}
@ -82,8 +82,7 @@ namespace rexy{
}
template<class T, class Allocator>
REXY_CPP20_CONSTEXPR buffer<T,Allocator>& buffer<T,Allocator>::operator=(const buffer& b)
noexcept(noexcept(this->allocate(0)) &&
noexcept(this->deallocate(nullptr, 0)))
noexcept(is_nothrow_allocator_v<Allocator>)
{
return (*this = buffer(b));
}