Add missing exception specs to basic_string and basic_string_view. Also implement some missing std functionality to them

This commit is contained in:
rexy712 2022-07-20 19:13:21 -07:00
parent 2fe6f0b4e1
commit eafe6f5a21
6 changed files with 927 additions and 286 deletions

View File

@ -253,7 +253,7 @@ namespace rexy{
}
template<class T, class Char, std::enable_if_t<is_string<T>::value, int> = 0>
constexpr std::size_t find_first_of(T&& t, const Char* c, std::size_t start, std::size_t size){
constexpr std::size_t find_first_of(T&& t, const Char* c, std::size_t start, std::size_t size)noexcept{
if(start > t.length()){
return rexy::npos;
}
@ -268,7 +268,27 @@ namespace rexy{
}
template<class T, class Char, std::enable_if_t<is_string<T>::value, int> = 0>
constexpr std::size_t find_last_of(T&& t, const Char* c, std::size_t start, std::size_t size){
constexpr std::size_t find_first_not_of(T&& t, const Char* c, std::size_t start, std::size_t size)noexcept{
if(start > t.length()){
return rexy::npos;
}
for(auto it = t.cbegin() + start;it != t.cend();++it){
bool found = false;
for(std::size_t i = 0;i < size;++i){
if(*it == c[i]){
found = true;
break;
}
}
if(!found){
return it - t.cbegin();
}
}
return rexy::npos;
}
template<class T, class Char, std::enable_if_t<is_string<T>::value, int> = 0>
constexpr std::size_t find_last_of(T&& t, const Char* c, std::size_t start, std::size_t size)noexcept{
if(start > t.length()){
return rexy::npos;
}
@ -286,6 +306,31 @@ namespace rexy{
return rexy::npos;
}
template<class T, class Char, std::enable_if_t<is_string<T>::value, int> = 0>
constexpr std::size_t find_last_not_of(T&& t, const Char* c, std::size_t start, std::size_t size)noexcept{
if(start > t.length()){
return rexy::npos;
}
const auto b = t.cend() - 1;
const auto e = t.cbegin() - 1 - start;
for(auto it = b;it != e;--it){
bool found = false;
for(std::size_t i = 0;i < size;++i){
if(*it == c[i]){
found = true;
break;
}
}
if(!found){
return it - t.cbegin();
}
}
return rexy::npos;
}
}
#endif

View File

@ -174,7 +174,7 @@ namespace rexy{
}
template<BasicString T, class Char>
constexpr std::size_t find_first_of(T&& t, const Char* c, std::size_t start, std::size_t size){
constexpr std::size_t find_first_of(T&& t, const Char* c, std::size_t start, std::size_t size)noexcept{
if(start > t.length()){
return rexy::npos;
}
@ -189,7 +189,27 @@ namespace rexy{
}
template<BasicString T, class Char>
constexpr std::size_t find_last_of(T&& t, const Char* c, std::size_t start, std::size_t size){
constexpr std::size_t find_first_not_of(T&& t, const Char* c, std::size_t start, std::size_t size)noexcept{
if(start > t.length()){
return rexy::npos;
}
for(auto it = t.cbegin() + start;it != t.cend();++it){
bool found = false;
for(std::size_t i = 0;i < size;++i){
if(*it == c[i]){
found = true;
break;
}
}
if(!found){
return it - t.cbegin();
}
}
return rexy::npos;
}
template<BasicString T, class Char>
constexpr std::size_t find_last_of(T&& t, const Char* c, std::size_t start, std::size_t size)noexcept{
if(start > t.length()){
return rexy::npos;
}
@ -207,6 +227,31 @@ namespace rexy{
return rexy::npos;
}
template<BasicString T, class Char>
constexpr std::size_t find_last_not_of(T&& t, const Char* c, std::size_t start, std::size_t size)noexcept{
if(start > t.length()){
return rexy::npos;
}
const auto b = t.cend() - 1;
const auto e = t.cbegin() - 1 - start;
for(auto it = b;it != e;--it){
bool found = false;
for(std::size_t i = 0;i < size;++i){
if(*it == c[i]){
found = true;
break;
}
}
if(!found){
return it - t.cbegin();
}
}
return rexy::npos;
}
}
#endif

View File

@ -278,23 +278,27 @@ namespace rexy{
constexpr reference at(size_type i)noexcept{return get_pointer()[i];}
constexpr const_reference at(size_type i)const noexcept{return get_pointer()[i];}
constexpr const_iterator search(basic_string_view<value_type> sv)const;
constexpr iterator search(basic_string_view<value_type> sv);
constexpr const_iterator search(const_pointer c)const;
constexpr iterator search(const_pointer c);
constexpr const_iterator search(basic_string_view<value_type> sv)const noexcept;
constexpr iterator search(basic_string_view<value_type> sv)noexcept;
constexpr const_iterator search(const_pointer c)const noexcept;
constexpr iterator search(const_pointer c)noexcept;
template<class Searcher>
constexpr const_iterator search(const_pointer c, const Searcher& searcher)const;
constexpr const_iterator search(const_pointer c, const Searcher& searcher)const noexcept(
std::is_nothrow_invocable_v<Searcher, const_iterator, const_iterator, const_pointer, const_pointer>);
template<class Searcher>
constexpr iterator search(const_pointer c, const Searcher& searcher);
constexpr iterator search(const_pointer c, const Searcher& searcher)noexcept(
std::is_nothrow_invocable_v<Searcher, iterator, iterator, const_pointer, const_pointer>);
constexpr const_iterator rsearch(basic_string_view<value_type> sv)const;
constexpr iterator rsearch(basic_string_view<value_type> sv);
constexpr const_iterator rsearch(const_pointer c)const;
constexpr iterator rsearch(const_pointer c);
constexpr const_iterator rsearch(basic_string_view<value_type> sv)const noexcept;
constexpr iterator rsearch(basic_string_view<value_type> sv)noexcept;
constexpr const_iterator rsearch(const_pointer c)const noexcept;
constexpr iterator rsearch(const_pointer c)noexcept;
template<class Searcher>
constexpr const_iterator rsearch(const_pointer c, const Searcher& searcher)const;
constexpr const_iterator rsearch(const_pointer c, const Searcher& searcher)const noexcept(
std::is_nothrow_invocable_v<Searcher, const_iterator, const_iterator, const_pointer, const_pointer>);
template<class Searcher>
constexpr iterator rsearch(const_pointer c, const Searcher& searcher);
constexpr iterator rsearch(const_pointer c, const Searcher& searcher)noexcept(
std::is_nothrow_invocable_v<Searcher, iterator, iterator, const_pointer, const_pointer>);
constexpr bool starts_with(basic_string_view<value_type> sv)const noexcept;
constexpr bool starts_with(value_type v)const noexcept;
@ -309,41 +313,75 @@ namespace rexy{
constexpr bool contains(const_pointer str)const noexcept;
//TODO more compares
constexpr bool compare(const string_base& s)const{return *this == s;}
constexpr bool compare(basic_string_view<value_type> s)const{return *this == s;}
constexpr bool compare(const_pointer c)const{return *this == c;}
constexpr bool compare(const string_base& s)const noexcept{return *this == s;}
constexpr bool compare(basic_string_view<value_type> s)const noexcept{return *this == s;}
constexpr bool compare(const_pointer c)const noexcept{return *this == c;}
constexpr size_type find_first_of(value_type v, size_type start = 0)const;
constexpr size_type find_first_of(const_pointer c, size_type pos = 0)const;
constexpr size_type find_first_of(const_pointer c, size_type pos, size_type size)const;
constexpr size_type find_last_of(value_type v, size_type start = 0)const;
constexpr size_type find_last_of(const_pointer c, size_type pos = 0)const;
constexpr size_type find_last_of(const_pointer c, size_type pos, size_type size)const;
constexpr size_type find_first_of(value_type v, size_type start = 0)const noexcept;
constexpr size_type find_first_of(const_pointer c, size_type start = 0)const noexcept;
constexpr size_type find_first_of(const_pointer c, size_type start, size_type size)const noexcept;
template<class StringView>
constexpr auto find_first_of(const StringView& str, size_type start = 0)const noexcept(
std::is_nothrow_convertible_v<const StringView&,basic_string_view<value_type>>) ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>>,
size_type>;
constexpr size_type find_last_of(value_type v, size_type start = 0)const noexcept;
constexpr size_type find_last_of(const_pointer c, size_type start = 0)const noexcept;
constexpr size_type find_last_of(const_pointer c, size_type start, size_type size)const noexcept;
template<class StringView>
constexpr auto find_last_of(const StringView& str, size_type start = 0)const noexcept(
std::is_nothrow_convertible_v<const StringView&,basic_string_view<value_type>>) ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>>,
size_type>;
constexpr size_type find_first_not_of(const_pointer str, size_type start, size_type count)const noexcept;
constexpr size_type find_first_not_of(const_pointer str, size_type start = 0)const noexcept;
constexpr size_type find_first_not_of(value_type v, size_type start = 0)const noexcept;
template<class StringView>
constexpr auto find_first_not_of(const StringView& str, size_type start = 0)const noexcept(
std::is_nothrow_convertible_v<const StringView&,basic_string_view<value_type>>) ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>>,
size_type>;
constexpr size_type find_last_not_of(const_pointer str, size_type start, size_type count)const noexcept;
constexpr size_type find_last_not_of(const_pointer str, size_type start = 0)const noexcept;
constexpr size_type find_last_not_of(value_type v, size_type start = 0)const noexcept;
template<class StringView>
constexpr auto find_last_not_of(const StringView& str, size_type start = 0)const noexcept(
std::is_nothrow_convertible_v<const StringView&,basic_string_view<value_type>>) ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>>,
size_type>;
constexpr reference front(void)noexcept{return *get_pointer();}
constexpr const_reference front(void)const noexcept{return *get_pointer();}
constexpr reference back(void)noexcept{return *(get_pointer() + length() - 1);}
constexpr const_reference back(void)const noexcept{return *(get_pointer() + length() - 1);}
constexpr iterator begin(void){return get_pointer();}
constexpr const_iterator begin(void)const{return get_pointer();}
constexpr iterator end(void){return get_pointer()+length();}
constexpr const_iterator end(void)const{return get_pointer()+length();}
constexpr const_iterator cbegin(void)const{return begin();}
constexpr const_iterator cend(void)const{return end();}
constexpr iterator begin(void)noexcept{return get_pointer();}
constexpr const_iterator begin(void)const noexcept{return get_pointer();}
constexpr iterator end(void)noexcept{return get_pointer()+length();}
constexpr const_iterator end(void)const noexcept{return get_pointer()+length();}
constexpr const_iterator cbegin(void)const noexcept{return begin();}
constexpr const_iterator cend(void)const noexcept{return end();}
constexpr reverse_iterator rbegin(void){return reverse_iterator(get_pointer()+length());}
constexpr const_reverse_iterator rbegin(void)const{return const_reverse_iterator(get_pointer()+length());}
constexpr reverse_iterator rend(void){return reverse_iterator(get_pointer());}
constexpr const_reverse_iterator rend(void)const{return const_reverse_iterator(get_pointer());}
constexpr const_reverse_iterator crbegin(void)const{return rbegin();}
constexpr const_reverse_iterator crend(void)const{return rend();}
constexpr reverse_iterator rbegin(void)noexcept{return reverse_iterator(get_pointer()+length());}
constexpr const_reverse_iterator rbegin(void)const noexcept{return const_reverse_iterator(get_pointer()+length());}
constexpr reverse_iterator rend(void)noexcept{return reverse_iterator(get_pointer());}
constexpr const_reverse_iterator rend(void)const noexcept{return const_reverse_iterator(get_pointer());}
constexpr const_reverse_iterator crbegin(void)const noexcept{return rbegin();}
constexpr const_reverse_iterator crend(void)const noexcept{return rend();}
constexpr void clear(void)noexcept;
constexpr basic_string_view<value_type> create_view(void)const noexcept;
constexpr basic_string_view<value_type> create_view(const_iterator start, const_iterator fin)const noexcept;
};
}; //class string_base
//Supplies all functions that string_base can't implement
@ -367,125 +405,279 @@ namespace rexy{
static constexpr size_type npos = size_type(-1);
private:
REXY_CPP20_CONSTEXPR void _copy_construct_string(const_pointer data, size_type len, size_type cap)
noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR basic_string& _copy_string(const_pointer s, size_type len)
noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
void _copy_construct_string(const_pointer data, size_type len, size_type cap)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& _copy_string(const_pointer s, size_type len)noexcept(
is_nothrow_allocator_v<Alloc>);
template<class InputIt>
REXY_CPP20_CONSTEXPR basic_string& _insert_impl(size_type pos, InputIt start, size_type insert_count)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& _insert_impl(size_type pos, InputIt start, size_type insert_count)noexcept(
is_nothrow_allocator_v<Alloc>);
template<class InputIt>
constexpr basic_string& _replace_impl(size_type pos, size_type count, InputIt src, size_type count2);
constexpr basic_string& _replace_impl(size_type pos, size_type count, InputIt src, size_type count2)noexcept;
public:
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, size_type cap)noexcept;
constexpr basic_string(rexy::steal<pointer> data)noexcept;
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(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR basic_string(const_pointer data)noexcept(is_nothrow_allocator_v<Alloc>);
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(is_nothrow_allocator_v<Alloc>);
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(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string(const_pointer data)noexcept(
is_nothrow_allocator_v<Alloc>);
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(
is_nothrow_allocator_v<Alloc>);
template<class InputIt, class Enable = std::enable_if_t<is_legacy_input_iterator_v<InputIt>,int>>
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(is_nothrow_allocator_v<Alloc>);
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(
is_nothrow_allocator_v<Alloc>);
//normal copy and move ctors
REXY_CPP20_CONSTEXPR basic_string(const basic_string& b)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string(const basic_string& b)noexcept(
is_nothrow_allocator_v<Alloc>);
constexpr basic_string(basic_string&& s)noexcept;
REXY_CPP20_CONSTEXPR basic_string(const string_base<Char>&)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string(const string_base<Char>&)noexcept(
is_nothrow_allocator_v<Alloc>);
//dtor
REXY_CPP20_CONSTEXPR ~basic_string(void)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
~basic_string(void)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR basic_string& operator=(const basic_string& s)
noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& operator=(const basic_string& s)noexcept(
is_nothrow_allocator_v<Alloc>);
constexpr basic_string& operator=(basic_string&& s)noexcept;
REXY_CPP20_CONSTEXPR basic_string& operator=(const string_base<Char>& s)
noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR basic_string& operator=(const basic_string_view<Char>& sv)
noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& operator=(const string_base<Char>& s)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& operator=(const basic_string_view<Char>& sv)noexcept(
is_nothrow_allocator_v<Alloc>);
//Copy from c string
REXY_CPP20_CONSTEXPR basic_string& operator=(const_pointer c)
noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& operator=(const_pointer c)noexcept(
is_nothrow_allocator_v<Alloc>);
//These can't be put in base because they require us to know the type of Alloc
constexpr size_type find_first_of(const basic_string& str, size_type start = 0)const noexcept;
constexpr size_type find_last_of(const basic_string& str, size_type start = 0)const noexcept;
constexpr size_type find_first_not_of(const basic_string& str, size_type start = 0)const noexcept;
constexpr size_type find_last_not_of(const basic_string& str, size_type start = 0)const noexcept;
//Replace managed pointer. Frees existing value
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(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR bool reserve(size_type newsize)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR void shrink_to_fit(void)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
void reset(pointer val = nullptr)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR void resize(size_type newsize, value_type v = value_type())noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
void reset(pointer val, size_type len)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
bool reserve(size_type newsize)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
void shrink_to_fit(void)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
void resize(size_type newsize, value_type v = value_type())noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& insert(size_type pos, size_type insert_count, value_type v)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& insert(size_type pos, value_type v)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& insert(size_type pos, const_pointer str)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& insert(size_type pos, const_pointer str, size_type insert_count)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& insert(size_type pos, const basic_string& other)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& insert(size_type pos, const basic_string& other, size_type index_str, size_type count = npos)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& insert(const_iterator pos, value_type v)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& insert(const_iterator pos, size_type count, value_type v)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR basic_string& insert(size_type pos, size_type insert_count, value_type v)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR basic_string& insert(size_type pos, value_type v)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR basic_string& insert(size_type pos, const_pointer str)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR basic_string& insert(size_type pos, const_pointer str, size_type insert_count)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR basic_string& insert(size_type pos, const basic_string& other)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR basic_string& insert(size_type pos, const basic_string& other, size_type index_str, size_type count = npos)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR basic_string& insert(const_iterator pos, value_type v)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR basic_string& insert(const_iterator pos, size_type count, value_type v)noexcept(is_nothrow_allocator_v<Alloc>);
template<class InputIt>
REXY_CPP20_CONSTEXPR auto insert(const_iterator pos, InputIt start, InputIt last)noexcept(is_nothrow_allocator_v<Alloc>) ->
REXY_CPP20_CONSTEXPR
auto insert(const_iterator pos, InputIt start, InputIt last)noexcept(
is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<is_legacy_input_iterator_v<InputIt>,basic_string&>;
template<class InputIt>
REXY_CPP20_CONSTEXPR auto insert(size_type pos, InputIt start, InputIt last)noexcept(is_nothrow_allocator_v<Alloc>) ->
REXY_CPP20_CONSTEXPR
auto insert(size_type pos, InputIt start, InputIt last)noexcept(
is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<is_legacy_input_iterator_v<InputIt>,basic_string&>;
REXY_CPP20_CONSTEXPR basic_string& insert(const_iterator pos, std::initializer_list<value_type> list)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& insert(const_iterator pos, std::initializer_list<value_type> list)noexcept(
is_nothrow_allocator_v<Alloc>);
template<class StringView>
REXY_CPP20_CONSTEXPR auto insert(size_type pos, const StringView& sv)noexcept(is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<std::is_convertible_v<const StringView&, basic_string_view<value_type>> && !std::is_convertible_v<const StringView&,const_pointer>,basic_string&>;
REXY_CPP20_CONSTEXPR
auto insert(size_type pos, const StringView& sv)noexcept(
is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>> &&
!std::is_convertible_v<const StringView&, const_pointer>,
basic_string&>;
template<class StringView>
REXY_CPP20_CONSTEXPR auto insert(size_type pos, const StringView& sv, size_type index_str, size_type count = npos)noexcept(is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<std::is_convertible_v<const StringView&, basic_string_view<value_type>> && !std::is_convertible_v<const StringView&,const_pointer>,basic_string&>;
REXY_CPP20_CONSTEXPR
auto insert(size_type pos, const StringView& sv, size_type index_str, size_type count = npos)noexcept(
is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>> &&
!std::is_convertible_v<const StringView&,const_pointer>,
basic_string&>;
template<class InputIt>
REXY_CPP20_CONSTEXPR auto append(InputIt start, InputIt fin)noexcept(is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<is_legacy_input_iterator_v<InputIt>,basic_string&>;
REXY_CPP20_CONSTEXPR basic_string& append(const_pointer data, size_type len)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR basic_string& append(const_pointer data)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR basic_string& append(const basic_string& other)noexcept(is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
auto append(InputIt start, InputIt fin)noexcept(
is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<is_legacy_input_iterator_v<InputIt>,basic_string&>;
REXY_CPP20_CONSTEXPR
basic_string& append(const_pointer data, size_type len)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& append(const_pointer data)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
basic_string& append(const basic_string& other)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
void push_back(value_type data)noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR void push_back(value_type data)noexcept(is_nothrow_allocator_v<Alloc>);
constexpr void pop_back(void)noexcept;
constexpr basic_string& replace(size_type pos, size_type count, const basic_string& str);
constexpr basic_string& replace(const_iterator pos, const_iterator last, const basic_string& str);
constexpr basic_string& replace(size_type pos, size_type count, const basic_string& str, size_type pos2, size_type count2 = npos);
constexpr basic_string& replace(size_type pos, size_type count, const basic_string& str)noexcept;
constexpr basic_string& replace(const_iterator pos, const_iterator last, const basic_string& str)noexcept;
constexpr basic_string& replace(size_type pos, size_type count, const basic_string& str, size_type pos2, size_type count2 = npos)noexcept;
template<class InputIt>
constexpr auto replace(const_iterator first, const_iterator last, InputIt first2, InputIt last2) ->
std::enable_if_t<is_legacy_input_iterator_v<InputIt>,basic_string&>;
constexpr basic_string& replace(size_type pos, size_type count, const_pointer cstr, size_type count2);
constexpr basic_string& replace(const_iterator first, const_iterator last, const_pointer cstr, size_type count);
constexpr basic_string& replace(size_type pos, size_type count, const_pointer cstr);
constexpr basic_string& replace(const_iterator first, const_iterator last, const_pointer cstr);
constexpr basic_string& replace(size_type pos, size_type count, size_type count2, value_type v);
constexpr basic_string& replace(const_iterator first, const_iterator last, size_type count2, value_type v);
constexpr basic_string& replace(const_iterator first, const_iterator last, std::initializer_list<value_type> list);
constexpr auto replace(const_iterator first, const_iterator last, InputIt first2, InputIt last2)noexcept ->
std::enable_if_t<is_legacy_input_iterator_v<InputIt>,basic_string&>;
constexpr basic_string& replace(size_type pos, size_type count, const_pointer cstr, size_type count2)noexcept;
constexpr basic_string& replace(const_iterator first, const_iterator last, const_pointer cstr, size_type count)noexcept;
constexpr basic_string& replace(size_type pos, size_type count, const_pointer cstr)noexcept;
constexpr basic_string& replace(const_iterator first, const_iterator last, const_pointer cstr)noexcept;
constexpr basic_string& replace(size_type pos, size_type count, size_type count2, value_type v)noexcept;
constexpr basic_string& replace(const_iterator first, const_iterator last, size_type count2, value_type v)noexcept;
constexpr basic_string& replace(const_iterator first, const_iterator last, std::initializer_list<value_type> list)noexcept;
template<class StringView>
constexpr auto replace(size_type pos, size_type count, const StringView& sv) ->
std::enable_if_t<std::is_convertible_v<const StringView&, basic_string_view<value_type>> && !std::is_convertible_v<const StringView&,const_pointer>,basic_string&>;
constexpr auto replace(size_type pos, size_type count, const StringView& sv)noexcept ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>> &&
!std::is_convertible_v<const StringView&,const_pointer>,
basic_string&>;
template<class StringView>
constexpr auto replace(const_iterator first, const_iterator last, const StringView& sv) ->
std::enable_if_t<std::is_convertible_v<const StringView&, basic_string_view<value_type>> && !std::is_convertible_v<const StringView&,const_pointer>,basic_string&>;
constexpr auto replace(const_iterator first, const_iterator last, const StringView& sv)noexcept ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>> &&
!std::is_convertible_v<const StringView&,const_pointer>,
basic_string&>;
template<class StringView>
constexpr auto replace(size_type pos, size_type count, const StringView& sv, size_type pos2, size_type count2 = npos) ->
std::enable_if_t<std::is_convertible_v<const StringView&, basic_string_view<value_type>> && !std::is_convertible_v<const StringView&,const_pointer>,basic_string&>;
constexpr auto replace(size_type pos, size_type count, const StringView& sv, size_type pos2, size_type count2 = npos)noexcept ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>> &&
!std::is_convertible_v<const StringView&,const_pointer>,
basic_string&>;
constexpr basic_string& erase(size_type index = 0, size_type count = npos)noexcept;
constexpr iterator erase(const_iterator pos)noexcept;
constexpr iterator erase(const_iterator first, const_iterator last)noexcept;
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 substr(size_type start, size_type end)const;
REXY_CPP20_CONSTEXPR pointer release(void)noexcept(is_nothrow_allocator_v<Alloc>);
template<REXY_ALLOCATOR_CONCEPT A = allocator_type>
REXY_CPP20_CONSTEXPR
basic_string<value_type,A> substring(size_type start, size_type end)const noexcept(
is_nothrow_allocator_v<A>);
REXY_CPP20_CONSTEXPR
basic_string substr(size_type start, size_type end)const noexcept(
is_nothrow_allocator_v<Alloc>);
REXY_CPP20_CONSTEXPR
pointer release(void)noexcept(
is_nothrow_allocator_v<Alloc>);
using detail::hasallocator<Alloc>::allocator;
};
}; //class basic_string
//Like an expression template but not really
template<class Left, class Right>
@ -514,14 +706,19 @@ namespace rexy{
constexpr size_type length(void)const noexcept;
template<REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR operator basic_string<value_type,Alloc>(void)
noexcept(std::is_nothrow_constructible<basic_string<value_type,Alloc>, typename basic_string<value_type,Alloc>::size_type>::value &&
std::is_nothrow_invocable<detail::string_appender<basic_string<value_type,Alloc>>,decltype(*this)>::value);
REXY_CPP20_CONSTEXPR
operator basic_string<value_type,Alloc>(void)noexcept(
std::is_nothrow_constructible_v<
basic_string<value_type,Alloc>,
typename basic_string<value_type,Alloc>::size_type> &&
std::is_nothrow_invocable_v<
detail::string_appender<basic_string<value_type,Alloc>>,
decltype(*this)>);
};
template<class Left, class Right>
string_cat_expr(Left&&,Right&&) -> string_cat_expr<Left&&,Right&&>;
}
} //namespace rexy
#include "string_base.tpp"

View File

@ -34,75 +34,83 @@
namespace rexy{
template<class Char>
constexpr auto string_base<Char>::search(basic_string_view<value_type> sv)const -> const_iterator{
constexpr auto string_base<Char>::search(basic_string_view<value_type> sv)const noexcept -> const_iterator{
if(sv.length() > length()){
return cend();
}
return two_way_search(cbegin(), cend(), sv.cbegin(), sv.cend());
}
template<class Char>
constexpr auto string_base<Char>::search(basic_string_view<value_type> sv) -> iterator{
constexpr auto string_base<Char>::search(basic_string_view<value_type> sv)noexcept -> iterator{
if(sv.length() > length()){
return end();
}
return two_way_search(begin(), end(), sv.cbegin(), sv.cend());
}
template<class Char>
constexpr auto string_base<Char>::search(const_pointer c)const -> const_iterator{
constexpr auto string_base<Char>::search(const_pointer c)const noexcept -> const_iterator{
const auto len = rexy::strlen(c);
return two_way_search(cbegin(), cend(), c, c + len);
}
template<class Char>
constexpr auto string_base<Char>::search(const_pointer c) -> iterator{
constexpr auto string_base<Char>::search(const_pointer c)noexcept -> iterator{
const auto len = rexy::strlen(c);
return two_way_search(begin(), end(), c, c + len);
}
template<class Char>
template<class Searcher>
constexpr auto string_base<Char>::search(const_pointer c, const Searcher& searcher)const -> const_iterator{
constexpr auto string_base<Char>::search(const_pointer c, const Searcher& searcher)const noexcept(
std::is_nothrow_invocable_v<Searcher, const_iterator, const_iterator, const_pointer, const_pointer>) -> const_iterator
{
const auto len = rexy::strlen(c);
return searcher(cbegin(), cend(), c, c + len);
}
template<class Char>
template<class Searcher>
constexpr auto string_base<Char>::search(const_pointer c, const Searcher& searcher) -> iterator{
constexpr auto string_base<Char>::search(const_pointer c, const Searcher& searcher)noexcept(
std::is_nothrow_invocable_v<Searcher, iterator, iterator, const_pointer, const_pointer>) -> iterator
{
const auto len = rexy::strlen(c);
return searcher(begin(), end(), c, c + len);
}
template<class Char>
constexpr auto string_base<Char>::rsearch(basic_string_view<value_type> sv)const -> const_iterator{
constexpr auto string_base<Char>::rsearch(basic_string_view<value_type> sv)const noexcept-> const_iterator{
if(sv.length() > length()){
return cend();
}
return two_way_search(crbegin(), crend(), sv.crbegin(), sv.crend()).base();
}
template<class Char>
constexpr auto string_base<Char>::rsearch(basic_string_view<value_type> sv) -> iterator{
constexpr auto string_base<Char>::rsearch(basic_string_view<value_type> sv)noexcept -> iterator{
if(sv.length() > length()){
return end();
}
return two_way_search(rbegin(), rend(), sv.crbegin(), sv.crend()).base() - sv.length();
}
template<class Char>
constexpr auto string_base<Char>::rsearch(const_pointer c)const -> const_iterator{
constexpr auto string_base<Char>::rsearch(const_pointer c)const noexcept -> const_iterator{
const auto len = rexy::strlen(c);
return two_way_search(crbegin(), crend(), std::reverse_iterator(c + len), std::reverse_iterator(c)).base() - len;
}
template<class Char>
constexpr auto string_base<Char>::rsearch(const_pointer c) -> iterator{
constexpr auto string_base<Char>::rsearch(const_pointer c)noexcept -> iterator{
const auto len = rexy::strlen(c);
return two_way_search(rbegin(), rend(), std::reverse_iterator(c + len), std::reverse_iterator(c)).base() - len;
}
template<class Char>
template<class Searcher>
constexpr auto string_base<Char>::rsearch(const_pointer c, const Searcher& searcher)const -> const_iterator{
constexpr auto string_base<Char>::rsearch(const_pointer c, const Searcher& searcher)const noexcept(
std::is_nothrow_invocable_v<Searcher, const_iterator, const_iterator, const_pointer, const_pointer>) -> const_iterator
{
const auto len = rexy::strlen(c);
return searcher(crbegin(), crend(), std::reverse_iterator(c + len), std::reverse_iterator(c)).base() - len;
}
template<class Char>
template<class Searcher>
constexpr auto string_base<Char>::rsearch(const_pointer c, const Searcher& searcher) -> iterator{
constexpr auto string_base<Char>::rsearch(const_pointer c, const Searcher& searcher)noexcept(
std::is_nothrow_invocable_v<Searcher, iterator, iterator, const_pointer, const_pointer>) -> iterator
{
const auto len = rexy::strlen(c);
return searcher(rbegin(), rend(), std::reverse_iterator(c + len), std::reverse_iterator(c)).base() - len;
}
@ -146,28 +154,101 @@ namespace rexy{
}
template<class Char>
constexpr auto string_base<Char>::find_first_of(value_type v, size_type start)const -> size_type{
constexpr auto string_base<Char>::find_first_of(value_type v, size_type start)const noexcept-> size_type{
return rexy::find_first_of(*this, &v, start, 1);
}
template<class Char>
constexpr auto string_base<Char>::find_first_of(const_pointer c, size_type pos)const -> size_type{
return rexy::find_first_of(*this, c, pos, rexy::strlen(c));
constexpr auto string_base<Char>::find_first_of(const_pointer c, size_type start)const noexcept -> size_type{
return rexy::find_first_of(*this, c, start, rexy::strlen(c));
}
template<class Char>
constexpr auto string_base<Char>::find_first_of(const_pointer c, size_type pos, size_type size)const -> size_type{
return rexy::find_first_of(*this, c, pos, size);
constexpr auto string_base<Char>::find_first_of(const_pointer c, size_type start, size_type size)const noexcept -> size_type{
return rexy::find_first_of(*this, c, start, size);
}
template<class Char>
constexpr auto string_base<Char>::find_last_of(value_type v, size_type start)const -> size_type{
template<class StringView>
constexpr auto string_base<Char>::find_first_of(const StringView& str, size_type start)const noexcept(
std::is_nothrow_convertible_v<const StringView&,basic_string_view<value_type>>) ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>>,
size_type>
{
const basic_string_view<value_type> tmp(str);
return rexy::find_first_of(*this, tmp.c_str(), start, tmp.length());
}
template<class Char>
constexpr auto string_base<Char>::find_last_of(value_type v, size_type start)const noexcept -> size_type{
return rexy::find_last_of(*this, &v, start, 1);
}
template<class Char>
constexpr auto string_base<Char>::find_last_of(const_pointer c, size_type pos)const -> size_type{
return rexy::find_last_of(*this, c, pos, rexy::strlen(c));
constexpr auto string_base<Char>::find_last_of(const_pointer c, size_type start)const noexcept -> size_type{
return rexy::find_last_of(*this, c, start, rexy::strlen(c));
}
template<class Char>
constexpr auto string_base<Char>::find_last_of(const_pointer c, size_type pos, size_type size)const -> size_type{
return rexy::find_last_of(*this, c, pos, size);
constexpr auto string_base<Char>::find_last_of(const_pointer c, size_type start, size_type size)const noexcept -> size_type{
return rexy::find_last_of(*this, c, start, size);
}
template<class Char>
template<class StringView>
constexpr auto string_base<Char>::find_last_of(const StringView& str, size_type start)const noexcept(
std::is_nothrow_convertible_v<const StringView&,basic_string_view<value_type>>) ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>>,
size_type>
{
const rexy::basic_string_view<value_type> tmp(str);
return rexy::find_last_of(*this, tmp.c_str(), start, tmp.length());
}
template<class Char>
constexpr auto string_base<Char>::find_first_not_of(const_pointer str, size_type start, size_type count)const noexcept -> size_type{
return rexy::find_first_not_of(*this, str, start, count);
}
template<class Char>
constexpr auto string_base<Char>::find_first_not_of(const_pointer str, size_type start)const noexcept -> size_type{
return rexy::find_first_not_of(*this, str, start, rexy::strlen(str));
}
template<class Char>
constexpr auto string_base<Char>::find_first_not_of(value_type v, size_type start)const noexcept -> size_type{
return rexy::find_first_not_of(*this, &v, start, 1);
}
template<class Char>
template<class StringView>
constexpr auto string_base<Char>::find_first_not_of(const StringView& str, size_type start)const noexcept(
std::is_nothrow_convertible_v<const StringView&,basic_string_view<value_type>>) ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>>,
size_type>
{
const basic_string_view<value_type> tmp(str);
return rexy::find_first_not_of(*this, tmp.c_str(), start, tmp.length());
}
template<class Char>
constexpr auto string_base<Char>::find_last_not_of(const_pointer str, size_type start, size_type count)const noexcept -> size_type{
return rexy::find_last_not_of(*this, str, start, count);
}
template<class Char>
constexpr auto string_base<Char>::find_last_not_of(const_pointer str, size_type start)const noexcept -> size_type{
return rexy::find_last_not_of(*this, str, start, rexy::strlen(str));
}
template<class Char>
constexpr auto string_base<Char>::find_last_not_of(value_type v, size_type start)const noexcept -> size_type{
return rexy::find_last_not_of(*this, &v, start, 1);
}
template<class Char>
template<class StringView>
constexpr auto string_base<Char>::find_last_not_of(const StringView& str, size_type start)const noexcept(
std::is_nothrow_convertible_v<const StringView&,basic_string_view<value_type>>) ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>>,
size_type>
{
const basic_string_view<value_type> tmp(str);
return rexy::find_last_not_of(*this, tmp.c_str(), start, tmp.length());
}
@ -191,8 +272,9 @@ namespace rexy{
//allocate string if longer than small string capacity, copy otherwise
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)
noexcept(is_nothrow_allocator_v<Alloc>)
REXY_CPP20_CONSTEXPR
void basic_string<Char,Alloc>::_copy_construct_string(const_pointer data, size_type len, size_type cap)noexcept(
is_nothrow_allocator_v<Alloc>)
{
if constexpr(string_base<Char>::uses_sso()){
if(cap > string_base<Char>::short_string_size()){
@ -228,50 +310,66 @@ namespace rexy{
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr basic_string<Char,Alloc>::basic_string(void)noexcept{}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr basic_string<Char,Alloc>::basic_string(rexy::steal<pointer> data)noexcept:
basic_string(data.value(), data.value() ? rexy::strlen(data.value()) : 0){}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr basic_string<Char,Alloc>::basic_string(rexy::steal<pointer> data, size_type len)noexcept:
string_base<Char>(data.value(), len, len){}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr basic_string<Char,Alloc>::basic_string(rexy::steal<pointer> data, size_type len, size_type cap)noexcept:
string_base<Char>(data.value(), len, cap){}
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)
noexcept(is_nothrow_allocator_v<Alloc>)
REXY_CPP20_CONSTEXPR
basic_string<Char,Alloc>::basic_string(const_pointer data, size_type len, size_type cap)noexcept(
is_nothrow_allocator_v<Alloc>)
{
_copy_construct_string(data, len, cap);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const_pointer data, size_type len)
noexcept(is_nothrow_allocator_v<Alloc>):
REXY_CPP20_CONSTEXPR
basic_string<Char,Alloc>::basic_string(const_pointer data, size_type len)noexcept(
is_nothrow_allocator_v<Alloc>):
basic_string(data, len, len){}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const_pointer data)
noexcept(is_nothrow_allocator_v<Alloc>):
REXY_CPP20_CONSTEXPR
basic_string<Char,Alloc>::basic_string(const_pointer data)noexcept(
is_nothrow_allocator_v<Alloc>):
basic_string(data, data ? rexy::strlen(data) : 0){}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(size_type cap)
noexcept(is_nothrow_allocator_v<Alloc>):
REXY_CPP20_CONSTEXPR
basic_string<Char,Alloc>::basic_string(size_type cap)noexcept(
is_nothrow_allocator_v<Alloc>):
basic_string(size_type(0), cap){}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(size_type len, size_type cap)
noexcept(is_nothrow_allocator_v<Alloc>)
REXY_CPP20_CONSTEXPR
basic_string<Char,Alloc>::basic_string(size_type len, size_type cap)noexcept(
is_nothrow_allocator_v<Alloc>)
{
_copy_construct_string(nullptr, len, cap);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const basic_string_view<Char>& sv)
noexcept(is_nothrow_allocator_v<Alloc>)
REXY_CPP20_CONSTEXPR
basic_string<Char,Alloc>::basic_string(const basic_string_view<Char>& sv)noexcept(
is_nothrow_allocator_v<Alloc>)
{
_copy_construct_string(sv.c_str(), sv.length(), sv.length());
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
template<class InputIt, class Enable>
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(InputIt start, InputIt fin)
noexcept(is_nothrow_allocator_v<Alloc>):
REXY_CPP20_CONSTEXPR
basic_string<Char,Alloc>::basic_string(InputIt start, InputIt fin)noexcept(
is_nothrow_allocator_v<Alloc>):
basic_string(nullptr, size_type(fin - start))
{
auto raw = this->get_pointer();
@ -281,38 +379,47 @@ namespace rexy{
}
raw[i] = 0;
}
//normal copy and move ctors
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const basic_string& b)
noexcept(is_nothrow_allocator_v<Alloc>):
REXY_CPP20_CONSTEXPR
basic_string<Char,Alloc>::basic_string(const basic_string& b)noexcept(
is_nothrow_allocator_v<Alloc>):
detail::hasallocator<Alloc>(b)
{
_copy_construct_string(b.data(), b.length(), b.length());
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr basic_string<Char,Alloc>::basic_string(basic_string&& s)noexcept:
detail::hasallocator<Alloc>(std::move(s)),
string_base<Char>(std::move(s)){}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::basic_string(const string_base<Char>& b)
noexcept(is_nothrow_allocator_v<Alloc>)
REXY_CPP20_CONSTEXPR
basic_string<Char,Alloc>::basic_string(const string_base<Char>& b)noexcept(
is_nothrow_allocator_v<Alloc>)
{
_copy_construct_string(b.data(), b.length(), b.length());
}
//dtor
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>::~basic_string(void)
noexcept(is_nothrow_allocator_v<Alloc>)
REXY_CPP20_CONSTEXPR
basic_string<Char,Alloc>::~basic_string(void)noexcept(
is_nothrow_allocator_v<Alloc>)
{
if(this->islong()){
this->deallocate(this->get_pointer(), sizeof(value_type)*(this->capacity()+1));
}
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(const basic_string& s)
noexcept(is_nothrow_allocator_v<Alloc>)
REXY_CPP20_CONSTEXPR
basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(const basic_string& s)noexcept(
is_nothrow_allocator_v<Alloc>)
{
if(s.length() < this->capacity()){
rexy::memcpy(this->get_pointer(), s.get_pointer(), sizeof(value_type)*(s.length()+1));
@ -323,42 +430,69 @@ namespace rexy{
return (*this = std::move(tmp));
}
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(basic_string&& s)noexcept{
string_base<Char>::operator=(std::move(s));
return *this;
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(const string_base<Char>& s)
noexcept(is_nothrow_allocator_v<Alloc>)
REXY_CPP20_CONSTEXPR
basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(const string_base<Char>& s)noexcept(
is_nothrow_allocator_v<Alloc>)
{
return (*this = basic_string(s));
}
//Copy from c string
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)
noexcept(is_nothrow_allocator_v<Alloc>)
REXY_CPP20_CONSTEXPR
basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(const basic_string_view<Char>& sv)noexcept(
is_nothrow_allocator_v<Alloc>)
{
return _copy_string(sv.c_str(), sv.length());
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(const_pointer c)
noexcept(is_nothrow_allocator_v<Alloc>)
REXY_CPP20_CONSTEXPR
basic_string<Char,Alloc>& basic_string<Char,Alloc>::operator=(const_pointer c)noexcept(
is_nothrow_allocator_v<Alloc>)
{
return _copy_string(c, rexy::strlen(c));
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::find_first_of(const basic_string& str, size_type start)const noexcept -> size_type{
return rexy::find_first_of(*this, str.c_str(), start, str.length());
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::find_last_of(const basic_string& str, size_type start)const noexcept -> size_type{
return rexy::find_last_of(*this, str.c_str(), start, str.length());
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::find_first_not_of(const basic_string& str, size_type start)const noexcept -> size_type{
return rexy::find_first_not_of(*this, str.c_str(), start, str.length());
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::find_last_not_of(const basic_string& str, size_type start)const noexcept -> size_type{
return rexy::find_last_not_of(*this, str.c_str(), start, str.length());
}
//Replace managed pointer. Frees existing value
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::reset(pointer val)
noexcept(is_nothrow_allocator_v<Alloc>)
REXY_CPP20_CONSTEXPR
void basic_string<Char,Alloc>::reset(pointer val)noexcept(
is_nothrow_allocator_v<Alloc>)
{
reset(val, val ? rexy::strlen(val) : 0);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::reset(pointer val, size_type len)
noexcept(is_nothrow_allocator_v<Alloc>)
REXY_CPP20_CONSTEXPR
void basic_string<Char,Alloc>::reset(pointer val, size_type len)noexcept(
is_nothrow_allocator_v<Alloc>)
{
if(this->islong())
this->deallocate(this->get_pointer(),sizeof(value_type)*(this->capacity()+1));
@ -371,23 +505,35 @@ namespace rexy{
this->set_capacity(len);
}
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR bool basic_string<Char,Alloc>::reserve(size_type newsize)noexcept(is_nothrow_allocator_v<Alloc>){
REXY_CPP20_CONSTEXPR
bool basic_string<Char,Alloc>::reserve(size_type newsize)noexcept(
is_nothrow_allocator_v<Alloc>)
{
if(newsize < this->capacity())
return false;
if(!this->islong() && newsize < string_base<Char>::short_string_size())
return false;
return (*this = basic_string(this->get_pointer(), newsize)).valid();
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::shrink_to_fit(void)noexcept(is_nothrow_allocator_v<Alloc>){
REXY_CPP20_CONSTEXPR
void basic_string<Char,Alloc>::shrink_to_fit(void)noexcept(
is_nothrow_allocator_v<Alloc>)
{
if(this->length() == this->capacity()){
return;
}
*this = basic_string(this->get_pointer(), this->length(), this->length());
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::resize(size_type newsize, value_type v)noexcept(is_nothrow_allocator_v<Alloc>){
REXY_CPP20_CONSTEXPR
void basic_string<Char,Alloc>::resize(size_type newsize, value_type v)noexcept(
is_nothrow_allocator_v<Alloc>)
{
const auto len = this->length();
const auto copy_count = std::min(newsize, len);
const auto insert_count = newsize > len ? newsize - len : 0;
@ -409,122 +555,204 @@ namespace rexy{
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::insert(size_type pos, size_type insert_count, value_type v)noexcept(is_nothrow_allocator_v<Alloc>) -> basic_string&{
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::insert(size_type pos, size_type insert_count, value_type v)noexcept(
is_nothrow_allocator_v<Alloc>) -> basic_string&
{
return _insert_impl(pos, constant_iterator{v}, insert_count);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::insert(size_type pos, value_type v)noexcept(is_nothrow_allocator_v<Alloc>) -> basic_string&{
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::insert(size_type pos, value_type v)noexcept(
is_nothrow_allocator_v<Alloc>) -> basic_string&
{
return _insert_impl(pos, &v, 1);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::insert(size_type pos, const_pointer str)noexcept(is_nothrow_allocator_v<Alloc>) -> basic_string&{
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::insert(size_type pos, const_pointer str)noexcept(
is_nothrow_allocator_v<Alloc>) -> basic_string&
{
return _insert_impl(pos, str, rexy::strlen(str));
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::insert(size_type pos, const_pointer str, size_type insert_count)noexcept(is_nothrow_allocator_v<Alloc>) -> basic_string&{
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::insert(size_type pos, const_pointer str, size_type insert_count)noexcept(
is_nothrow_allocator_v<Alloc>) -> basic_string&
{
return _insert_impl(pos, str, insert_count);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::insert(size_type pos, const basic_string& other)noexcept(is_nothrow_allocator_v<Alloc>) -> basic_string&{
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::insert(size_type pos, const basic_string& other)noexcept(
is_nothrow_allocator_v<Alloc>) -> basic_string&
{
return _insert_impl(pos, other.begin(), other.length());
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::insert(size_type pos, const basic_string& other, size_type index_str, size_type count)noexcept(is_nothrow_allocator_v<Alloc>) -> basic_string&{
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::insert(size_type pos, const basic_string& other, size_type index_str, size_type count)noexcept(
is_nothrow_allocator_v<Alloc>) -> basic_string&
{
return _insert_impl(pos, other.begin() + index_str, count);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::insert(const_iterator pos, value_type v)noexcept(is_nothrow_allocator_v<Alloc>) -> basic_string&{
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::insert(const_iterator pos, value_type v)noexcept(
is_nothrow_allocator_v<Alloc>) -> basic_string&
{
return _insert_impl(pos - this->begin(), &v, 1);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::insert(const_iterator pos, size_type count, value_type v)noexcept(is_nothrow_allocator_v<Alloc>) -> basic_string&{
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::insert(const_iterator pos, size_type count, value_type v)noexcept(
is_nothrow_allocator_v<Alloc>) -> basic_string&
{
return insert(pos - this->begin(), count, v);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
template<class InputIt>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::insert(const_iterator pos, InputIt start, InputIt last)noexcept(is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<is_legacy_input_iterator_v<InputIt>,basic_string&>
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::insert(const_iterator pos, InputIt start, InputIt last)noexcept(
is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<is_legacy_input_iterator_v<InputIt>,basic_string&>
{
return insert(pos - this->begin(), std::move(start), std::move(last));
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::insert(const_iterator pos, std::initializer_list<value_type> list)noexcept(is_nothrow_allocator_v<Alloc>) -> basic_string&{
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::insert(const_iterator pos, std::initializer_list<value_type> list)noexcept(
is_nothrow_allocator_v<Alloc>) -> basic_string&
{
return insert(pos, list.begin(), list.end());
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
template<class StringView>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::insert(size_type pos, const StringView& sv)noexcept(is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<std::is_convertible_v<const StringView&, basic_string_view<value_type>> && !std::is_convertible_v<const StringView&,const_pointer>,basic_string&>
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::insert(size_type pos, const StringView& sv)noexcept(
is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>> &&
!std::is_convertible_v<const StringView&,const_pointer>,
basic_string&>
{
return insert(pos, sv.begin(), sv.end());
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
template<class StringView>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::insert(size_type pos, const StringView& sv, size_type index_str, size_type count)noexcept(is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<std::is_convertible_v<const StringView&, basic_string_view<value_type>> && !std::is_convertible_v<const StringView&,const_pointer>,basic_string&>
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::insert(size_type pos, const StringView& sv, size_type index_str, size_type count)noexcept(
is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>> &&
!std::is_convertible_v<const StringView&,const_pointer>,
basic_string&>
{
return insert(pos, sv.begin() + index_str, sv.begin() + index_str + count);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
template<class InputIt>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::insert(size_type pos, InputIt start, InputIt last)noexcept(is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<is_legacy_input_iterator_v<InputIt>,basic_string&>
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::insert(size_type pos, InputIt start, InputIt last)noexcept(
is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<is_legacy_input_iterator_v<InputIt>,basic_string&>
{
size_type insert_count = 0;
for(auto it = start;it != last;++it, ++insert_count){}
return _insert_impl(pos, start, insert_count);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::append(const_pointer data, size_type len)noexcept(is_nothrow_allocator_v<Alloc>) -> basic_string&{
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::append(const_pointer data, size_type len)noexcept(
is_nothrow_allocator_v<Alloc>) -> basic_string&
{
return _insert_impl(this->length(), data, len);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::append(const_pointer data)noexcept(is_nothrow_allocator_v<Alloc>) -> basic_string&{
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::append(const_pointer data)noexcept(
is_nothrow_allocator_v<Alloc>) -> basic_string&
{
if(data){
append(data, rexy::strlen(data));
}
return *this;
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::append(const basic_string& other)noexcept(is_nothrow_allocator_v<Alloc>) -> basic_string&{
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::append(const basic_string& other)noexcept(
is_nothrow_allocator_v<Alloc>) -> basic_string&
{
return _insert_impl(this->length(), other.data(), other.length());
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
template<class InputIt>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::append(InputIt start, InputIt fin)noexcept(is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<is_legacy_input_iterator_v<InputIt>,basic_string&>
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::append(InputIt start, InputIt fin)noexcept(
is_nothrow_allocator_v<Alloc>) ->
std::enable_if_t<is_legacy_input_iterator_v<InputIt>,basic_string&>
{
return insert(this->length(), start, fin);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::push_back(value_type data)
noexcept(is_nothrow_allocator_v<Alloc>)
REXY_CPP20_CONSTEXPR
void basic_string<Char,Alloc>::push_back(value_type data)noexcept(
is_nothrow_allocator_v<Alloc>)
{
append(&data, 1);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr void basic_string<Char,Alloc>::pop_back(void)noexcept{
erase(this->end() - 1);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::replace(size_type pos, size_type count, const basic_string& str) -> basic_string&{
constexpr auto basic_string<Char,Alloc>::replace(size_type pos, size_type count, const basic_string& str)noexcept -> basic_string&{
return replace(pos, count, str.create_view());
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::replace(const_iterator first, const_iterator last, const basic_string& str) -> basic_string&{
constexpr auto basic_string<Char,Alloc>::replace(
const_iterator first, const_iterator last,
const basic_string& str)noexcept -> basic_string&
{
return replace(first, last, str.create_view());
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::replace(size_type pos, size_type count, const basic_string& str, size_type pos2, size_type count2) -> basic_string&{
constexpr auto basic_string<Char,Alloc>::replace(
size_type pos, size_type count,
const basic_string& str, size_type pos2, size_type count2)noexcept -> basic_string&
{
return replace(pos, count, str.create_view(), pos2, count2);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
template<class InputIt>
constexpr auto basic_string<Char,Alloc>::replace(const_iterator first, const_iterator last, InputIt first2, InputIt last2) ->
constexpr auto basic_string<Char,Alloc>::replace(const_iterator first, const_iterator last, InputIt first2, InputIt last2)noexcept ->
std::enable_if_t<is_legacy_input_iterator_v<InputIt>,basic_string&>
{
const size_type len = last - first;
@ -532,52 +760,88 @@ namespace rexy{
for(auto it = first2;count < len && it != last2;++count,++it);
return _replace_impl(size_type(first - this->begin()), len, first2, count);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::replace(size_type pos, size_type count, const_pointer cstr, size_type count2) -> basic_string&{
constexpr auto basic_string<Char,Alloc>::replace(
size_type pos, size_type count,
const_pointer cstr, size_type count2)noexcept -> basic_string&
{
return _replace_impl(pos, count, cstr, count2);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::replace(const_iterator first, const_iterator last, const_pointer cstr, size_type count) -> basic_string&{
constexpr auto basic_string<Char,Alloc>::replace(
const_iterator first, const_iterator last,
const_pointer cstr, size_type count)noexcept -> basic_string&
{
return _replace_impl(size_type(first - this->begin()), size_type(last - first), cstr, count);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::replace(size_type pos, size_type count, const_pointer cstr) -> basic_string&{
constexpr auto basic_string<Char,Alloc>::replace(size_type pos, size_type count, const_pointer cstr)noexcept -> basic_string&{
return _replace_impl(pos, count, cstr, rexy::strlen(cstr));
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::replace(const_iterator first, const_iterator last, const_pointer cstr) -> basic_string&{
constexpr auto basic_string<Char,Alloc>::replace(const_iterator first, const_iterator last, const_pointer cstr)noexcept -> basic_string&{
return _replace_impl(size_type(first - this->begin()), size_type(last - first), cstr, rexy::strlen(cstr));
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::replace(size_type pos, size_type count, size_type count2, value_type v) -> basic_string&{
constexpr auto basic_string<Char,Alloc>::replace(
size_type pos, size_type count,
size_type count2, value_type v)noexcept -> basic_string&
{
return _replace_impl(pos, count, constant_iterator{v}, count2);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::replace(const_iterator first, const_iterator last, size_type count2, value_type v) -> basic_string&{
constexpr auto basic_string<Char,Alloc>::replace(
const_iterator first, const_iterator last,
size_type count2, value_type v)noexcept -> basic_string&
{
return _replace_impl(size_type(first - this->begin()), size_type(last - first), constant_iterator{v}, count2);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::replace(const_iterator first, const_iterator last, std::initializer_list<value_type> list) -> basic_string&{
constexpr auto basic_string<Char,Alloc>::replace(
const_iterator first, const_iterator last,
std::initializer_list<value_type> list)noexcept -> basic_string&
{
return _replace_impl(size_type(first - this->begin()), size_type(last - first), list.begin(), list.size());
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
template<class StringView>
constexpr auto basic_string<Char,Alloc>::replace(size_type pos, size_type count, const StringView& sv) ->
std::enable_if_t<std::is_convertible_v<const StringView&, basic_string_view<value_type>> && !std::is_convertible_v<const StringView&,const_pointer>,basic_string&>
constexpr auto basic_string<Char,Alloc>::replace(size_type pos, size_type count, const StringView& sv)noexcept ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>> &&
!std::is_convertible_v<const StringView&,const_pointer>,
basic_string&>
{
return _replace_impl(pos, count, sv.begin(), sv.length());
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
template<class StringView>
constexpr auto basic_string<Char,Alloc>::replace(const_iterator first, const_iterator last, const StringView& sv) ->
std::enable_if_t<std::is_convertible_v<const StringView&, basic_string_view<value_type>> && !std::is_convertible_v<const StringView&,const_pointer>,basic_string&>
constexpr auto basic_string<Char,Alloc>::replace(const_iterator first, const_iterator last, const StringView& sv)noexcept ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>> &&
!std::is_convertible_v<const StringView&,const_pointer>,
basic_string&>
{
return _replace_impl(size_type(first - this->begin()), size_type(last - first), sv.begin(), sv.length());
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
template<class StringView>
constexpr auto basic_string<Char,Alloc>::replace(size_type pos, size_type count, const StringView& sv, size_type pos2, size_type count2) ->
std::enable_if_t<std::is_convertible_v<const StringView&, basic_string_view<value_type>> && !std::is_convertible_v<const StringView&,const_pointer>,basic_string&>
constexpr auto basic_string<Char,Alloc>::replace(
size_type pos, size_type count,
const StringView& sv, size_type pos2, size_type count2)noexcept ->
std::enable_if_t<
std::is_convertible_v<const StringView&, basic_string_view<value_type>> &&
!std::is_convertible_v<const StringView&,const_pointer>,
basic_string&>
{
if(pos2 > sv.length()){
pos2 = sv.length();
@ -590,6 +854,8 @@ namespace rexy{
return _replace_impl(pos, count, sv.begin() + pos2, maxlen2);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::erase(size_type index, size_type count)noexcept -> basic_string&{
const auto len = this->length();
@ -597,22 +863,22 @@ namespace rexy{
const auto end_pos = index + rem_count;
const auto relocate_count = len - end_pos + 1; //include terminator
{
auto* src = this->get_pointer() + end_pos;
auto* dst = this->get_pointer() + index;
for(size_type i = 0;i < relocate_count;++i){
*dst++ = *src++;
}
auto* src = this->get_pointer() + end_pos;
auto* dst = this->get_pointer() + index;
for(size_type i = 0;i < relocate_count;++i){
*dst++ = *src++;
}
this->set_length(len - rem_count);
return *this;
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::erase(const_iterator pos)noexcept -> iterator{
const auto pos_index = pos - this->begin();
erase(pos - this->begin(), 1);
return this->begin() + pos_index;
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
constexpr auto basic_string<Char,Alloc>::erase(const_iterator first, const_iterator last)noexcept -> iterator{
const auto distance = last - first;
@ -622,9 +888,13 @@ namespace rexy{
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
template<REXY_ALLOCATOR_CONCEPT A>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::substring(size_type start, size_type end)const -> basic_string<value_type,A>{
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::substring(size_type start, size_type end)const noexcept(
is_nothrow_allocator_v<A>) -> basic_string<value_type,A>
{
if(start > end || end > this->length())
return {};
const size_type newlen = end - start;
@ -632,13 +902,22 @@ namespace rexy{
tmp.append(this->data() + start, newlen);
return tmp;
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::substr(size_type start, size_type end)const -> basic_string{
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::substr(size_type start, size_type end)const noexcept(
is_nothrow_allocator_v<Alloc>) -> basic_string
{
return substring<allocator_type>(start, end);
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::release(void)noexcept(is_nothrow_allocator_v<Alloc>) -> pointer{
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::release(void)noexcept(
is_nothrow_allocator_v<Alloc>) -> pointer
{
if(this->islong()){
pointer raw = this->get_pointer();
this->set_short_ptr();
@ -659,10 +938,13 @@ namespace rexy{
}
}
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)
noexcept(is_nothrow_allocator_v<Alloc>)
{
REXY_CPP20_CONSTEXPR
basic_string<Char,Alloc>& basic_string<Char,Alloc>::_copy_string(const_pointer s, size_type len)noexcept(
is_nothrow_allocator_v<Alloc>)
{
if(!s || !len)
return (*this = basic_string(rexy::steal<pointer>(nullptr), 0, 0));
if(len <= this->length()){
@ -674,9 +956,13 @@ namespace rexy{
}
return (*this = basic_string(s, len));
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
template<class InputIt>
REXY_CPP20_CONSTEXPR auto basic_string<Char,Alloc>::_insert_impl(size_type pos, InputIt start, size_type insert_count)noexcept(is_nothrow_allocator_v<Alloc>) -> basic_string&{
REXY_CPP20_CONSTEXPR
auto basic_string<Char,Alloc>::_insert_impl(size_type pos, InputIt start, size_type insert_count)noexcept(
is_nothrow_allocator_v<Alloc>) -> basic_string&
{
const size_type len = this->length();
const size_type cap = this->capacity();
//add one for null terminator
@ -719,7 +1005,7 @@ namespace rexy{
}
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
template<class InputIt>
constexpr auto basic_string<Char,Alloc>::_replace_impl(size_type pos, size_type count, InputIt src, size_type count2) -> basic_string&{
constexpr auto basic_string<Char,Alloc>::_replace_impl(size_type pos, size_type count, InputIt src, size_type count2)noexcept -> basic_string&{
const auto len = this->length();
if(pos > len){
pos = len;
@ -745,9 +1031,14 @@ namespace rexy{
}
template<class Left, class Right>
template<REXY_ALLOCATOR_CONCEPT Alloc>
REXY_CPP20_CONSTEXPR string_cat_expr<Left,Right>::operator basic_string<typename string_cat_expr<Left,Right>::value_type,Alloc>(void)
noexcept(std::is_nothrow_constructible<basic_string<value_type,Alloc>, typename basic_string<value_type,Alloc>::size_type>::value &&
std::is_nothrow_invocable<detail::string_appender<basic_string<value_type,Alloc>>,decltype(*this)>::value)
REXY_CPP20_CONSTEXPR
string_cat_expr<Left,Right>::operator basic_string<typename string_cat_expr<Left,Right>::value_type,Alloc>(void)noexcept(
std::is_nothrow_constructible_v<
basic_string<value_type,Alloc>,
typename basic_string<value_type,Alloc>::size_type> &&
std::is_nothrow_invocable_v<
detail::string_appender<basic_string<value_type,Alloc>>,
decltype(*this)>)
{
size_type len = length();
basic_string<value_type,Alloc> ret(len);

View File

@ -83,49 +83,64 @@ namespace rexy{
constexpr const_reference back(void)const noexcept{return m_data[m_length-1];}
constexpr const_iterator it_at(size_type i)const noexcept{return m_data + i;}
constexpr const_iterator search(basic_string_view s)const;
constexpr const_iterator search(const_pointer c)const;
constexpr const_iterator search(basic_string_view s)const noexcept;
constexpr const_iterator search(const_pointer c)const noexcept;
template<class Searcher>
constexpr const_iterator search(basic_string_view s, const Searcher& searcher)const;
constexpr const_iterator search(basic_string_view s, const Searcher& searcher)const noexcept(
std::is_nothrow_invocable_v<Searcher, const_iterator, const_iterator, const_iterator, const_iterator>);
template<class Searcher>
constexpr const_iterator search(const_pointer c, const Searcher& searcher)const;
constexpr const_iterator search(const_pointer c, const Searcher& searcher)const noexcept(
std::is_nothrow_invocable_v<Searcher, const_iterator, const_iterator, const_pointer, const_pointer>);
constexpr bool starts_with(basic_string_view sv)const;
constexpr bool starts_with(value_type v)const;
constexpr bool starts_with(const_pointer str)const;
constexpr bool starts_with(basic_string_view sv)const noexcept;
constexpr bool starts_with(value_type v)const noexcept;
constexpr bool starts_with(const_pointer str)const noexcept;
constexpr bool ends_with(basic_string_view sv)const;
constexpr bool ends_with(value_type v)const;
constexpr bool ends_with(const_pointer str)const;
constexpr bool ends_with(basic_string_view sv)const noexcept;
constexpr bool ends_with(value_type v)const noexcept;
constexpr bool ends_with(const_pointer str)const noexcept;
constexpr bool contains(basic_string_view sv)const;
constexpr bool contains(value_type sv)const;
constexpr bool contains(const_pointer str)const;
constexpr bool contains(basic_string_view sv)const noexcept;
constexpr bool contains(value_type sv)const noexcept;
constexpr bool contains(const_pointer str)const noexcept;
constexpr bool compare(const basic_string_view& s)const{return *this == s;}
constexpr bool compare(const_pointer c)const{return *this == c;}
constexpr bool compare(const basic_string_view& s)const noexcept{return *this == s;}
constexpr bool compare(const_pointer c)const noexcept{return *this == c;}
constexpr const_iterator begin(void)const{return m_data;}
constexpr const_iterator end(void)const{return m_data+m_length;}
constexpr const_iterator cbegin(void)const{return begin();}
constexpr const_iterator cend(void)const{return end();}
constexpr const_iterator begin(void)const noexcept{return m_data;}
constexpr const_iterator end(void)const noexcept{return m_data+m_length;}
constexpr const_iterator cbegin(void)const noexcept{return begin();}
constexpr const_iterator cend(void)const noexcept{return end();}
constexpr const_reverse_iterator rbegin(void)const{return const_reverse_iterator(m_data+m_length);}
constexpr const_reverse_iterator rend(void)const{return const_reverse_iterator(m_data);}
constexpr const_reverse_iterator crbegin(void)const{return rbegin();}
constexpr const_reverse_iterator crend(void)const{return rend();}
constexpr const_reverse_iterator rbegin(void)const noexcept{return const_reverse_iterator(m_data+m_length);}
constexpr const_reverse_iterator rend(void)const noexcept{return const_reverse_iterator(m_data);}
constexpr const_reverse_iterator crbegin(void)const noexcept{return rbegin();}
constexpr const_reverse_iterator crend(void)const noexcept{return rend();}
constexpr void remove_prefix(size_type i);
constexpr void remove_suffix(size_type i);
constexpr void remove_prefix(size_type i)noexcept;
constexpr void remove_suffix(size_type i)noexcept;
constexpr basic_string_view substr(size_type pos, size_type count = npos)const;
constexpr basic_string_view substr(size_type pos, size_type count = npos)const noexcept;
constexpr size_type find_first_of(value_type v, size_type start = 0)const;
constexpr size_type find_first_of(const_pointer c, size_type pos = 0)const;
constexpr size_type find_first_of(const_pointer c, size_type pos, size_type size)const;
constexpr size_type find_last_of(value_type v, size_type start = 0)const;
constexpr size_type find_last_of(const_pointer c, size_type pos = 0)const;
constexpr size_type find_last_of(const_pointer c, size_type pos, size_type size)const;
constexpr size_type find_first_of(basic_string_view str, size_type pos = 0)const noexcept;
constexpr size_type find_first_of(value_type v, size_type start = 0)const noexcept;
constexpr size_type find_first_of(const_pointer c, size_type pos = 0)const noexcept;
constexpr size_type find_first_of(const_pointer c, size_type pos, size_type size)const noexcept;
constexpr size_type find_first_not_of(basic_string_view str, size_type pos = 0)const noexcept;
constexpr size_type find_first_not_of(value_type v, size_type start = 0)const noexcept;
constexpr size_type find_first_not_of(const_pointer c, size_type pos = 0)const noexcept;
constexpr size_type find_first_not_of(const_pointer c, size_type pos, size_type size)const noexcept;
constexpr size_type find_last_of(basic_string_view str, size_type pos = 0)const noexcept;
constexpr size_type find_last_of(value_type v, size_type start = 0)const noexcept;
constexpr size_type find_last_of(const_pointer c, size_type pos = 0)const noexcept;
constexpr size_type find_last_of(const_pointer c, size_type pos, size_type size)const noexcept;
constexpr size_type find_last_not_of(basic_string_view str, size_type pos = 0)const noexcept;
constexpr size_type find_last_not_of(value_type v, size_type start = 0)const noexcept;
constexpr size_type find_last_not_of(const_pointer c, size_type pos = 0)const noexcept;
constexpr size_type find_last_not_of(const_pointer c, size_type pos, size_type size)const noexcept;
};

View File

@ -50,20 +50,22 @@ namespace rexy{
}
template<class Char>
constexpr auto basic_string_view<Char>::search(basic_string_view s)const -> const_iterator{
constexpr auto basic_string_view<Char>::search(basic_string_view s)const noexcept -> const_iterator{
if(s.length() > m_length){
return cend();
}
return two_way_search(cbegin(), cend(), s.cbegin(), s.cend());
}
template<class Char>
constexpr auto basic_string_view<Char>::search(const_pointer c)const -> const_iterator{
constexpr auto basic_string_view<Char>::search(const_pointer c)const noexcept -> const_iterator{
basic_string_view tmp(c);
return search(tmp);
}
template<class Char>
template<class Searcher>
constexpr auto basic_string_view<Char>::search(basic_string_view s, const Searcher& searcher)const -> const_iterator{
constexpr auto basic_string_view<Char>::search(basic_string_view s, const Searcher& searcher)const noexcept(
std::is_nothrow_invocable_v<Searcher, const_iterator, const_iterator, const_iterator, const_iterator>) -> const_iterator
{
if(s.length() > m_length){
return cend();
}
@ -71,13 +73,15 @@ namespace rexy{
}
template<class Char>
template<class Searcher>
constexpr auto basic_string_view<Char>::search(const_pointer c, const Searcher& searcher)const -> const_iterator{
constexpr auto basic_string_view<Char>::search(const_pointer c, const Searcher& searcher)const noexcept(
std::is_nothrow_invocable_v<Searcher, const_iterator, const_iterator, const_pointer, const_pointer>) -> const_iterator
{
basic_string_view tmp(c);
return search(tmp, searcher);
}
template<class Char>
constexpr bool basic_string_view<Char>::starts_with(basic_string_view sv)const{
constexpr bool basic_string_view<Char>::starts_with(basic_string_view sv)const noexcept{
if(sv.length() > length()){
return false;
}
@ -88,16 +92,16 @@ namespace rexy{
return false;
}
template<class Char>
constexpr bool basic_string_view<Char>::starts_with(value_type v)const{
constexpr bool basic_string_view<Char>::starts_with(value_type v)const noexcept{
return front() == v;
}
template<class Char>
constexpr bool basic_string_view<Char>::starts_with(const_pointer s)const{
constexpr bool basic_string_view<Char>::starts_with(const_pointer s)const noexcept{
return starts_with(basic_string_view(s));
}
template<class Char>
constexpr bool basic_string_view<Char>::ends_with(basic_string_view sv)const{
constexpr bool basic_string_view<Char>::ends_with(basic_string_view sv)const noexcept{
if(sv.length() > length()){
return false;
}
@ -109,16 +113,16 @@ namespace rexy{
return false;
}
template<class Char>
constexpr bool basic_string_view<Char>::ends_with(value_type v)const{
constexpr bool basic_string_view<Char>::ends_with(value_type v)const noexcept{
return back() == v;
}
template<class Char>
constexpr bool basic_string_view<Char>::ends_with(const_pointer s)const{
constexpr bool basic_string_view<Char>::ends_with(const_pointer s)const noexcept{
return ends_with(basic_string_view(s));
}
template<class Char>
constexpr bool basic_string_view<Char>::contains(basic_string_view sv)const{
constexpr bool basic_string_view<Char>::contains(basic_string_view sv)const noexcept{
const auto it = two_way_search(cbegin(), cend(), sv.cbegin(), sv.cend());
if(it != cend()){
return true;
@ -126,7 +130,7 @@ namespace rexy{
return false;
}
template<class Char>
constexpr bool basic_string_view<Char>::contains(value_type v)const{
constexpr bool basic_string_view<Char>::contains(value_type v)const noexcept{
for(size_type i = 0;i < length();++i){
if(m_data[i] == v){
return true;
@ -135,19 +139,19 @@ namespace rexy{
return false;
}
template<class Char>
constexpr bool basic_string_view<Char>::contains(const_pointer str)const{
constexpr bool basic_string_view<Char>::contains(const_pointer str)const noexcept{
return contains(basic_string_view(str));
}
template<class Char>
constexpr basic_string_view<Char> basic_string_view<Char>::substr(size_type pos, size_type count)const{
constexpr basic_string_view<Char> basic_string_view<Char>::substr(size_type pos, size_type count)const noexcept{
const size_type real_count = rexy::min(count, length() - pos);
return basic_string_view{m_data + pos, real_count};
}
template<class Char>
constexpr void basic_string_view<Char>::remove_prefix(size_type i){
constexpr void basic_string_view<Char>::remove_prefix(size_type i) noexcept{
if(i > m_length){
m_data = end();
m_length = 0;
@ -157,38 +161,82 @@ namespace rexy{
}
}
template<class Char>
constexpr void basic_string_view<Char>::remove_suffix(size_type i){
constexpr void basic_string_view<Char>::remove_suffix(size_type i) noexcept{
if(i > m_length){
m_length = 0;
}else{
m_length -= i;
}
}
template<class Char>
constexpr auto basic_string_view<Char>::find_first_of(value_type v, size_type start)const -> size_type{
constexpr auto basic_string_view<Char>::find_first_of(basic_string_view str, size_type pos)const noexcept -> size_type{
return rexy::find_first_of(*this, str.c_str(), pos, str.length());
}
template<class Char>
constexpr auto basic_string_view<Char>::find_first_of(value_type v, size_type start)const noexcept -> size_type{
return rexy::find_first_of(*this, &v, start, 1);
}
template<class Char>
constexpr auto basic_string_view<Char>::find_first_of(const_pointer c, size_type start)const -> size_type{
constexpr auto basic_string_view<Char>::find_first_of(const_pointer c, size_type start)const noexcept -> size_type{
return rexy::find_first_of(*this, c, start, rexy::strlen(c));
}
template<class Char>
constexpr auto basic_string_view<Char>::find_first_of(const_pointer c, size_type start, size_type size)const -> size_type{
constexpr auto basic_string_view<Char>::find_first_of(const_pointer c, size_type start, size_type size)const noexcept -> size_type{
return rexy::find_first_of(*this, c, start, size);
}
template<class Char>
constexpr auto basic_string_view<Char>::find_last_of(value_type v, size_type start)const -> size_type{
constexpr auto basic_string_view<Char>::find_first_not_of(basic_string_view str, size_type pos)const noexcept -> size_type{
return rexy::find_first_not_of(*this, str.c_str(), pos, str.length());
}
template<class Char>
constexpr auto basic_string_view<Char>::find_first_not_of(value_type v, size_type start)const noexcept -> size_type{
return rexy::find_first_not_of(*this, &v, start, 1);
}
template<class Char>
constexpr auto basic_string_view<Char>::find_first_not_of(const_pointer c, size_type start)const noexcept -> size_type{
return rexy::find_first_not_of(*this, c, start, rexy::strlen(c));
}
template<class Char>
constexpr auto basic_string_view<Char>::find_first_not_of(const_pointer c, size_type start, size_type size)const noexcept -> size_type{
return rexy::find_first_not_of(*this, c, start, size);
}
template<class Char>
constexpr auto basic_string_view<Char>::find_last_of(basic_string_view str, size_type pos)const noexcept -> size_type{
return rexy::find_last_of(*this, str.c_str(), pos, str.length());
}
template<class Char>
constexpr auto basic_string_view<Char>::find_last_of(value_type v, size_type start)const noexcept -> size_type{
return rexy::find_last_of(*this, &v, start, 1);
}
template<class Char>
constexpr auto basic_string_view<Char>::find_last_of(const_pointer c, size_type start)const -> size_type{
constexpr auto basic_string_view<Char>::find_last_of(const_pointer c, size_type start)const noexcept -> size_type{
return rexy::find_last_of(*this, c, start, rexy::strlen(c));
}
template<class Char>
constexpr auto basic_string_view<Char>::find_last_of(const_pointer c, size_type start, size_type size)const -> size_type{
constexpr auto basic_string_view<Char>::find_last_of(const_pointer c, size_type start, size_type size)const noexcept -> size_type{
return rexy::find_last_of(*this, c, start, size);
}
template<class Char>
constexpr auto basic_string_view<Char>::find_last_not_of(basic_string_view str, size_type pos)const noexcept -> size_type{
return rexy::find_last_not_of(*this, str.c_str(), pos, str.length());
}
template<class Char>
constexpr auto basic_string_view<Char>::find_last_not_of(value_type v, size_type start)const noexcept -> size_type{
return rexy::find_last_not_of(*this, &v, start, 1);
}
template<class Char>
constexpr auto basic_string_view<Char>::find_last_not_of(const_pointer c, size_type start)const noexcept -> size_type{
return rexy::find_last_not_of(*this, c, start, rexy::strlen(c));
}
template<class Char>
constexpr auto basic_string_view<Char>::find_last_not_of(const_pointer c, size_type start, size_type size)const noexcept -> size_type{
return rexy::find_last_not_of(*this, c, start, size);
}
}
#endif