Add is_nothrow_allocator type trait
This commit is contained in:
parent
e96899ceba
commit
1acce4c588
@ -38,6 +38,8 @@
|
|||||||
#include "rexy.hpp"
|
#include "rexy.hpp"
|
||||||
#include "compat/standard.hpp"
|
#include "compat/standard.hpp"
|
||||||
|
|
||||||
|
#include <type_traits> //declval
|
||||||
|
|
||||||
namespace rexy{
|
namespace rexy{
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
@ -170,6 +172,13 @@ namespace rexy{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<REXY_ALLOCATOR_CONCEPT T>
|
||||||
|
struct is_nothrow_allocator{
|
||||||
|
static constexpr bool value = noexcept(std::declval<T>().allocate(0)) && noexcept(std::declval<T>().deallocate(nullptr, 0));
|
||||||
|
};
|
||||||
|
template<REXY_ALLOCATOR_CONCEPT T>
|
||||||
|
static constexpr bool is_nothrow_allocator_v = is_nothrow_allocator<T>::value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -31,17 +31,17 @@ namespace rexy::detail{
|
|||||||
{
|
{
|
||||||
Alloc m_alloc;
|
Alloc m_alloc;
|
||||||
|
|
||||||
REXY_CPP20_CONSTEXPR auto allocate(typename Alloc::size_type bytes)noexcept(noexcept(m_alloc.allocate(0))){
|
REXY_CPP20_CONSTEXPR auto allocate(typename Alloc::size_type bytes)noexcept(is_nothrow_allocator_v<Alloc>){
|
||||||
return m_alloc.allocate(bytes);
|
return m_alloc.allocate(bytes);
|
||||||
}
|
}
|
||||||
REXY_CPP20_CONSTEXPR void deallocate(typename Alloc::pointer p, typename Alloc::size_type bytes)noexcept(noexcept(m_alloc.deallocate(nullptr,0))){
|
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);
|
m_alloc.deallocate(p, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
Alloc& allocator(void){
|
constexpr Alloc& allocator(void){
|
||||||
return m_alloc;
|
return m_alloc;
|
||||||
}
|
}
|
||||||
const Alloc& allocator(void)const{
|
constexpr const Alloc& allocator(void)const{
|
||||||
return m_alloc;
|
return m_alloc;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -52,21 +52,21 @@ namespace rexy::detail{
|
|||||||
[[no_unique_address]]
|
[[no_unique_address]]
|
||||||
Alloc m_alloc;
|
Alloc m_alloc;
|
||||||
|
|
||||||
REXY_CPP20_CONSTEXPR auto allocate(typename Alloc::size_type bytes)noexcept(noexcept(m_alloc.allocate(0))){
|
REXY_CPP20_CONSTEXPR auto allocate(typename Alloc::size_type bytes)noexcept(is_nothrow_allocator_v<Alloc>){
|
||||||
return m_alloc.allocate(bytes);
|
return m_alloc.allocate(bytes);
|
||||||
}
|
}
|
||||||
REXY_CPP20_CONSTEXPR void deallocate(typename Alloc::pointer p, typename Alloc::size_type bytes)noexcept(noexcept(m_alloc.deallocate(nullptr,0))){
|
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);
|
m_alloc.deallocate(p, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
Alloc& allocator(void){
|
constexpr Alloc& allocator(void){
|
||||||
return m_alloc;
|
return m_alloc;
|
||||||
}
|
}
|
||||||
const Alloc& allocator(void)const{
|
constexpr const Alloc& allocator(void)const{
|
||||||
return m_alloc;
|
return m_alloc;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
#endif //no_unique_address
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -33,6 +33,7 @@
|
|||||||
#include "expression.hpp"
|
#include "expression.hpp"
|
||||||
#include "detail/string_appender.hpp"
|
#include "detail/string_appender.hpp"
|
||||||
#include "detail/hasallocator.hpp"
|
#include "detail/hasallocator.hpp"
|
||||||
|
#include "allocator.hpp"
|
||||||
#include "rexy.hpp"
|
#include "rexy.hpp"
|
||||||
|
|
||||||
#include "compat/standard.hpp"
|
#include "compat/standard.hpp"
|
||||||
@ -260,74 +261,64 @@ namespace rexy{
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
REXY_CPP20_CONSTEXPR void _copy_construct_string(const_pointer data, size_type len, size_type cap)
|
REXY_CPP20_CONSTEXPR void _copy_construct_string(const_pointer data, size_type len, size_type cap)
|
||||||
noexcept(noexcept(this->allocate(0)));
|
noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
REXY_CPP20_CONSTEXPR basic_string& _copy_string(const_pointer s, size_type len)
|
REXY_CPP20_CONSTEXPR basic_string& _copy_string(const_pointer s, size_type len)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
noexcept(this->deallocate(nullptr,0)));
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr basic_string(void)noexcept;
|
constexpr basic_string(void)noexcept;
|
||||||
constexpr basic_string(rexy::steal<pointer> data, size_type len)noexcept;
|
constexpr basic_string(rexy::steal<pointer> data, size_type len)noexcept;
|
||||||
constexpr basic_string(rexy::steal<pointer> data, size_type len, size_type cap)noexcept;
|
constexpr basic_string(rexy::steal<pointer> data, size_type len, size_type cap)noexcept;
|
||||||
constexpr basic_string(rexy::steal<pointer> data)noexcept;
|
constexpr basic_string(rexy::steal<pointer> data)noexcept;
|
||||||
REXY_CPP20_CONSTEXPR basic_string(const_pointer data, size_type len)noexcept(noexcept(this->allocate(0)));
|
REXY_CPP20_CONSTEXPR basic_string(const_pointer data, size_type len)noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
REXY_CPP20_CONSTEXPR basic_string(const_pointer data, size_type len, size_type cap)noexcept(noexcept(this->allocate(0)));
|
REXY_CPP20_CONSTEXPR basic_string(const_pointer data, size_type len, size_type cap)noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
REXY_CPP20_CONSTEXPR basic_string(const_pointer data)noexcept(noexcept(this->allocate(0)));
|
REXY_CPP20_CONSTEXPR basic_string(const_pointer data)noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
REXY_CPP20_CONSTEXPR explicit basic_string(size_type len)noexcept(noexcept(this->allocate(0)));
|
REXY_CPP20_CONSTEXPR explicit basic_string(size_type len)noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
REXY_CPP20_CONSTEXPR basic_string(size_type len, size_type cap)noexcept(noexcept(this->allocate(0)));
|
REXY_CPP20_CONSTEXPR basic_string(size_type len, size_type cap)noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
template<class InputIt>
|
template<class InputIt>
|
||||||
REXY_CPP20_CONSTEXPR basic_string(InputIt start, InputIt fin)noexcept(noexcept(this->allocate(0)));
|
REXY_CPP20_CONSTEXPR basic_string(InputIt start, InputIt fin)noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
REXY_CPP20_CONSTEXPR basic_string(const basic_string_view<Char>& sv)noexcept(noexcept(this->allocate(0)));
|
REXY_CPP20_CONSTEXPR basic_string(const basic_string_view<Char>& sv)noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
//normal copy and move ctors
|
//normal copy and move ctors
|
||||||
REXY_CPP20_CONSTEXPR basic_string(const basic_string& b)noexcept(noexcept(this->allocate(0)));
|
REXY_CPP20_CONSTEXPR basic_string(const basic_string& b)noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
constexpr basic_string(basic_string&& s)noexcept;
|
constexpr basic_string(basic_string&& s)noexcept;
|
||||||
REXY_CPP20_CONSTEXPR basic_string(const string_base<Char>&)noexcept(noexcept(this->allocate(0)));
|
REXY_CPP20_CONSTEXPR basic_string(const string_base<Char>&)noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
|
|
||||||
//dtor
|
//dtor
|
||||||
REXY_CPP20_CONSTEXPR ~basic_string(void)noexcept(noexcept(this->deallocate(nullptr, 0)));
|
REXY_CPP20_CONSTEXPR ~basic_string(void)noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
|
|
||||||
REXY_CPP20_CONSTEXPR basic_string& operator=(const basic_string& s)
|
REXY_CPP20_CONSTEXPR basic_string& operator=(const basic_string& s)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
noexcept(this->deallocate(nullptr,0)));
|
|
||||||
|
|
||||||
constexpr basic_string& operator=(basic_string&& s)noexcept;
|
constexpr basic_string& operator=(basic_string&& s)noexcept;
|
||||||
|
|
||||||
REXY_CPP20_CONSTEXPR basic_string& operator=(const string_base<Char>& s)
|
REXY_CPP20_CONSTEXPR basic_string& operator=(const string_base<Char>& s)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
noexcept(this->deallocate(nullptr,0)));
|
|
||||||
REXY_CPP20_CONSTEXPR basic_string& operator=(const basic_string_view<Char>& sv)
|
REXY_CPP20_CONSTEXPR basic_string& operator=(const basic_string_view<Char>& sv)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
noexcept(this->deallocate(nullptr,0)));
|
|
||||||
//Copy from c string
|
//Copy from c string
|
||||||
REXY_CPP20_CONSTEXPR basic_string& operator=(const_pointer c)
|
REXY_CPP20_CONSTEXPR basic_string& operator=(const_pointer c)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
noexcept(this->deallocate(nullptr,0)));
|
|
||||||
|
|
||||||
//Replace managed pointer. Frees existing value
|
//Replace managed pointer. Frees existing value
|
||||||
REXY_CPP20_CONSTEXPR void reset(pointer val = nullptr)noexcept(noexcept(this->deallocate(nullptr,0)));
|
REXY_CPP20_CONSTEXPR void reset(pointer val = nullptr)noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
REXY_CPP20_CONSTEXPR void reset(pointer val, size_type len)noexcept(noexcept(this->deallocate(nullptr,0)));
|
REXY_CPP20_CONSTEXPR void reset(pointer val, size_type len)noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
REXY_CPP20_CONSTEXPR bool resize(size_type newsize)
|
REXY_CPP20_CONSTEXPR bool resize(size_type newsize)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
noexcept(this->deallocate(nullptr,0)));
|
|
||||||
|
|
||||||
REXY_CPP20_CONSTEXPR void push_back(value_type data)
|
REXY_CPP20_CONSTEXPR void push_back(value_type data)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
noexcept(this->deallocate(nullptr,0)));
|
|
||||||
REXY_CPP20_CONSTEXPR void append(const_pointer data, size_type len)
|
REXY_CPP20_CONSTEXPR void append(const_pointer data, size_type len)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
noexcept(this->deallocate(nullptr,0)));
|
|
||||||
REXY_CPP20_CONSTEXPR void append(const_pointer data)
|
REXY_CPP20_CONSTEXPR void append(const_pointer data)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
noexcept(this->deallocate(nullptr,0)));
|
|
||||||
template<class InputIt>
|
template<class InputIt>
|
||||||
REXY_CPP20_CONSTEXPR void append(InputIt start, InputIt fin)
|
REXY_CPP20_CONSTEXPR void append(InputIt start, InputIt fin)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
noexcept(this->deallocate(nullptr,0)));
|
|
||||||
|
|
||||||
template<REXY_ALLOCATOR_CONCEPT A = allocator_type>
|
template<REXY_ALLOCATOR_CONCEPT A = allocator_type>
|
||||||
REXY_CPP20_CONSTEXPR basic_string<value_type,A> substring(size_type start, size_type end)const;
|
REXY_CPP20_CONSTEXPR basic_string<value_type,A> substring(size_type start, size_type end)const;
|
||||||
|
|
||||||
REXY_CPP20_CONSTEXPR pointer release(void)noexcept(noexcept(this->allocate(0)));
|
REXY_CPP20_CONSTEXPR pointer release(void)noexcept(is_nothrow_allocator_v<Alloc>);
|
||||||
using detail::hasallocator<Alloc>::allocator;
|
using detail::hasallocator<Alloc>::allocator;
|
||||||
|
|
||||||
constexpr basic_string_view<value_type> create_view(void)const noexcept;
|
constexpr basic_string_view<value_type> create_view(void)const noexcept;
|
||||||
|
|||||||
@ -82,7 +82,7 @@ namespace rexy{
|
|||||||
//allocate string if longer than small string capacity, copy otherwise
|
//allocate string if longer than small string capacity, copy otherwise
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::_copy_construct_string(const_pointer data, size_type len, size_type cap)
|
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::_copy_construct_string(const_pointer data, size_type len, size_type cap)
|
||||||
noexcept(noexcept(this->allocate(0)))
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
{
|
{
|
||||||
if(cap > this->get_short_capacity()){
|
if(cap > this->get_short_capacity()){
|
||||||
this->set_islong_flag(true);
|
this->set_islong_flag(true);
|
||||||
@ -116,31 +116,31 @@ namespace rexy{
|
|||||||
string_base<Char>(data.value(), len, cap){}
|
string_base<Char>(data.value(), len, cap){}
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const_pointer data, size_type len, size_type cap)
|
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const_pointer data, size_type len, size_type cap)
|
||||||
noexcept(noexcept(this->allocate(0)))
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
{
|
{
|
||||||
_copy_construct_string(data, len, cap);
|
_copy_construct_string(data, len, cap);
|
||||||
}
|
}
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const_pointer data, size_type len)
|
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const_pointer data, size_type len)
|
||||||
noexcept(noexcept(this->allocate(0))):
|
noexcept(is_nothrow_allocator_v<Alloc>):
|
||||||
basic_string(data, len, len){}
|
basic_string(data, len, len){}
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const_pointer data)
|
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const_pointer data)
|
||||||
noexcept(noexcept(this->allocate(0))):
|
noexcept(is_nothrow_allocator_v<Alloc>):
|
||||||
basic_string(data, data ? strlen(data) : 0){}
|
basic_string(data, data ? strlen(data) : 0){}
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(size_type cap)
|
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(size_type cap)
|
||||||
noexcept(noexcept(this->allocate(0))):
|
noexcept(is_nothrow_allocator_v<Alloc>):
|
||||||
basic_string(size_type{0}, cap){}
|
basic_string(size_type{0}, cap){}
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(size_type len, size_type cap)
|
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(size_type len, size_type cap)
|
||||||
noexcept(noexcept(this->allocate(0)))
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
{
|
{
|
||||||
_copy_construct_string(nullptr, len, cap);
|
_copy_construct_string(nullptr, len, cap);
|
||||||
}
|
}
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const basic_string_view<Char>& sv)
|
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const basic_string_view<Char>& sv)
|
||||||
noexcept(noexcept(this->allocate(0)))
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
{
|
{
|
||||||
_copy_construct_string(sv.c_str(), sv.length(), sv.length());
|
_copy_construct_string(sv.c_str(), sv.length(), sv.length());
|
||||||
}
|
}
|
||||||
@ -148,7 +148,7 @@ namespace rexy{
|
|||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
template<class InputIt>
|
template<class InputIt>
|
||||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(InputIt start, InputIt fin)
|
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(InputIt start, InputIt fin)
|
||||||
noexcept(noexcept(this->allocate(0))):
|
noexcept(is_nothrow_allocator_v<Alloc>):
|
||||||
basic_string(nullptr, size_type{fin - start})
|
basic_string(nullptr, size_type{fin - start})
|
||||||
{
|
{
|
||||||
auto raw = this->get_pointer();
|
auto raw = this->get_pointer();
|
||||||
@ -161,7 +161,7 @@ namespace rexy{
|
|||||||
//normal copy and move ctors
|
//normal copy and move ctors
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const basic_string& b)
|
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const basic_string& b)
|
||||||
noexcept(noexcept(this->allocate(0))):
|
noexcept(is_nothrow_allocator_v<Alloc>):
|
||||||
detail::hasallocator<Alloc>(b)
|
detail::hasallocator<Alloc>(b)
|
||||||
{
|
{
|
||||||
_copy_construct_string(b.get(), b.length(), b.capacity());
|
_copy_construct_string(b.get(), b.length(), b.capacity());
|
||||||
@ -172,7 +172,7 @@ namespace rexy{
|
|||||||
string_base<Char>(std::move(s)){}
|
string_base<Char>(std::move(s)){}
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const string_base<Char>& b)
|
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const string_base<Char>& b)
|
||||||
noexcept(noexcept(this->allocate(0)))
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
{
|
{
|
||||||
_copy_construct_string(b.get(), b.length(), b.capacity());
|
_copy_construct_string(b.get(), b.length(), b.capacity());
|
||||||
}
|
}
|
||||||
@ -180,7 +180,7 @@ namespace rexy{
|
|||||||
//dtor
|
//dtor
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::~basic_string(void)
|
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::~basic_string(void)
|
||||||
noexcept(noexcept(this->deallocate(nullptr, 0)))
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
{
|
{
|
||||||
if(this->islong()){
|
if(this->islong()){
|
||||||
this->deallocate(this->get_pointer(), sizeof(value_type)*(this->get_long_capacity()+1));
|
this->deallocate(this->get_pointer(), sizeof(value_type)*(this->get_long_capacity()+1));
|
||||||
@ -189,8 +189,7 @@ namespace rexy{
|
|||||||
|
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(const basic_string& s)
|
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(const basic_string& s)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
noexcept(this->deallocate(nullptr, 0)))
|
|
||||||
{
|
{
|
||||||
if(s.length() < this->capacity()){
|
if(s.length() < this->capacity()){
|
||||||
memcpy(this->get_pointer(), s.get_pointer(), sizeof(value_type)*(s.length()+1));
|
memcpy(this->get_pointer(), s.get_pointer(), sizeof(value_type)*(s.length()+1));
|
||||||
@ -207,24 +206,21 @@ namespace rexy{
|
|||||||
}
|
}
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(const string_base<Char>& s)
|
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(const string_base<Char>& s)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
noexcept(this->deallocate(nullptr,0)))
|
|
||||||
{
|
{
|
||||||
return (*this = basic_string(s));
|
return (*this = basic_string(s));
|
||||||
}
|
}
|
||||||
//Copy from c string
|
//Copy from c string
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(const basic_string_view<Char>& sv)
|
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(const basic_string_view<Char>& sv)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
noexcept(this->deallocate(nullptr,0)))
|
|
||||||
{
|
{
|
||||||
return _copy_string(sv.c_str(), sv.length());
|
return _copy_string(sv.c_str(), sv.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(const_pointer c)
|
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(const_pointer c)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
noexcept(this->deallocate(nullptr,0)))
|
|
||||||
{
|
{
|
||||||
return _copy_string(c, strlen(c));
|
return _copy_string(c, strlen(c));
|
||||||
}
|
}
|
||||||
@ -232,13 +228,13 @@ namespace rexy{
|
|||||||
//Replace managed pointer. Frees existing value
|
//Replace managed pointer. Frees existing value
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::reset(pointer val)
|
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::reset(pointer val)
|
||||||
noexcept(noexcept(this->deallocate(nullptr,0)))
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
{
|
{
|
||||||
reset(val, val ? strlen(val) : 0);
|
reset(val, val ? strlen(val) : 0);
|
||||||
}
|
}
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::reset(pointer val, size_type len)
|
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::reset(pointer val, size_type len)
|
||||||
noexcept(noexcept(this->deallocate(nullptr,0)))
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
{
|
{
|
||||||
if(this->islong())
|
if(this->islong())
|
||||||
this->deallocate(this->get_long_ptr(),sizeof(value_type)*(this->get_long_capacity()+1));
|
this->deallocate(this->get_long_ptr(),sizeof(value_type)*(this->get_long_capacity()+1));
|
||||||
@ -249,8 +245,7 @@ namespace rexy{
|
|||||||
}
|
}
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR bool basic_string<Char,Alloc>::resize(size_type newsize)
|
REXY_CPP20_CONSTEXPR bool basic_string<Char,Alloc>::resize(size_type newsize)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
noexcept(this->deallocate(nullptr,0)))
|
|
||||||
{
|
{
|
||||||
if(newsize < this->capacity())
|
if(newsize < this->capacity())
|
||||||
return false;
|
return false;
|
||||||
@ -261,16 +256,14 @@ namespace rexy{
|
|||||||
|
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::push_back(value_type data)
|
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::push_back(value_type data)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
noexcept(this->deallocate(nullptr,0)))
|
|
||||||
{
|
{
|
||||||
append(&data, 1);
|
append(&data, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::append(const_pointer data, size_type len)
|
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::append(const_pointer data, size_type len)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
noexcept(this->deallocate(nullptr,0)))
|
|
||||||
{
|
{
|
||||||
size_type mylen = this->length();
|
size_type mylen = this->length();
|
||||||
size_type mycap = this->capacity();
|
size_type mycap = this->capacity();
|
||||||
@ -290,8 +283,7 @@ namespace rexy{
|
|||||||
}
|
}
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::append(const_pointer data)
|
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::append(const_pointer data)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
noexcept(this->deallocate(nullptr,0)))
|
|
||||||
{
|
{
|
||||||
if(data)
|
if(data)
|
||||||
append(data, strlen(data));
|
append(data, strlen(data));
|
||||||
@ -299,8 +291,7 @@ namespace rexy{
|
|||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
template<class InputIt>
|
template<class InputIt>
|
||||||
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::append(InputIt start, InputIt fin)
|
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::append(InputIt start, InputIt fin)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
noexcept(this->deallocate(nullptr,0)))
|
|
||||||
{
|
{
|
||||||
size_type append_len = fin - start;
|
size_type append_len = fin - start;
|
||||||
|
|
||||||
@ -334,7 +325,7 @@ namespace rexy{
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::release(void)noexcept(noexcept(this->allocate(0))) -> pointer{
|
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::release(void)noexcept(is_nothrow_allocator_v<Alloc>) -> pointer{
|
||||||
if(this->islong()){
|
if(this->islong()){
|
||||||
pointer raw = this->get_long_ptr();
|
pointer raw = this->get_long_ptr();
|
||||||
this->set_islong_flag(false);
|
this->set_islong_flag(false);
|
||||||
@ -363,8 +354,7 @@ namespace rexy{
|
|||||||
|
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>& basic_string<Char,Alloc>::_copy_string(const_pointer s, size_type len)
|
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>& basic_string<Char,Alloc>::_copy_string(const_pointer s, size_type len)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(is_nothrow_allocator_v<Alloc>)
|
||||||
noexcept(this->deallocate(nullptr,0)))
|
|
||||||
{
|
{
|
||||||
if(!s || !len)
|
if(!s || !len)
|
||||||
return (*this = basic_string(rexy::steal<pointer>(nullptr), 0, 0));
|
return (*this = basic_string(rexy::steal<pointer>(nullptr), 0, 0));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user