Update detail::value_iterator to become constant_iterator
This commit is contained in:
parent
858f7533e6
commit
c4d83b0310
@ -23,7 +23,7 @@
|
|||||||
#include <type_traits> //is_nothrow_invokable, is_nothrow_constructible
|
#include <type_traits> //is_nothrow_invokable, is_nothrow_constructible
|
||||||
#include <iterator> //reverse_iterator
|
#include <iterator> //reverse_iterator
|
||||||
|
|
||||||
#include "utility.hpp" //max, memcpy, strlen
|
#include "utility.hpp" //max, memcpy, strlen, constant_iterator
|
||||||
#include "detail/string_appender.hpp"
|
#include "detail/string_appender.hpp"
|
||||||
#include "algorithm.hpp"
|
#include "algorithm.hpp"
|
||||||
#include "compat/to_address.hpp"
|
#include "compat/to_address.hpp"
|
||||||
@ -33,23 +33,6 @@
|
|||||||
|
|
||||||
namespace rexy{
|
namespace rexy{
|
||||||
|
|
||||||
namespace detail{
|
|
||||||
template<class T>
|
|
||||||
struct value_iterator_adapter{
|
|
||||||
T val;
|
|
||||||
|
|
||||||
constexpr value_iterator_adapter& operator++(void)noexcept{return *this;}
|
|
||||||
constexpr value_iterator_adapter operator++(int)noexcept{return *this;}
|
|
||||||
constexpr T operator*(void)const noexcept{return val;}
|
|
||||||
|
|
||||||
constexpr bool operator==(const value_iterator_adapter& other)const{return val == other.val;}
|
|
||||||
constexpr bool operator!=(const value_iterator_adapter& other)const{return val == other.val;}
|
|
||||||
|
|
||||||
};
|
|
||||||
template<class T>
|
|
||||||
value_iterator_adapter(T) -> value_iterator_adapter<T>;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class Char>
|
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 -> const_iterator{
|
||||||
if(sv.length() > length()){
|
if(sv.length() > length()){
|
||||||
@ -427,7 +410,7 @@ namespace rexy{
|
|||||||
|
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
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, detail::value_iterator_adapter{v}, insert_count);
|
return _insert_impl(pos, constant_iterator{v}, insert_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
@ -567,11 +550,11 @@ namespace rexy{
|
|||||||
}
|
}
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
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) -> basic_string&{
|
||||||
return _replace_impl(pos, count, detail::value_iterator_adapter{v}, count2);
|
return _replace_impl(pos, count, constant_iterator{v}, count2);
|
||||||
}
|
}
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
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) -> basic_string&{
|
||||||
return _replace_impl(size_type(first - this->begin()), size_type(last - first), detail::value_iterator_adapter{v}, count2);
|
return _replace_impl(size_type(first - this->begin()), size_type(last - first), constant_iterator{v}, count2);
|
||||||
}
|
}
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
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) -> basic_string&{
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include "compat/if_consteval.hpp"
|
#include "compat/if_consteval.hpp"
|
||||||
#include "rexy.hpp"
|
#include "rexy.hpp"
|
||||||
|
#include "storage_for.hpp"
|
||||||
|
|
||||||
#ifdef REXY_if_consteval
|
#ifdef REXY_if_consteval
|
||||||
#include <cstring> //strlen, strcmp, memcpy
|
#include <cstring> //strlen, strcmp, memcpy
|
||||||
@ -180,6 +181,52 @@ namespace rexy{
|
|||||||
}
|
}
|
||||||
#endif // REXY_if_consteval
|
#endif // REXY_if_consteval
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct constant_iterator
|
||||||
|
{
|
||||||
|
rexy::storage_for<T> val;
|
||||||
|
|
||||||
|
constexpr constant_iterator& operator++(void)noexcept{return *this;}
|
||||||
|
constexpr constant_iterator operator++(int)noexcept{return *this;}
|
||||||
|
constexpr T operator*(void)const noexcept{return val;}
|
||||||
|
|
||||||
|
constexpr bool operator==(const constant_iterator& other)const{return val == other.val;}
|
||||||
|
constexpr bool operator!=(const constant_iterator& other)const{return val != other.val;}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
constant_iterator(T&&) -> constant_iterator<std::remove_cvref_t<T>>;
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct sized_constant_iterator
|
||||||
|
{
|
||||||
|
rexy::storage_for<T> val;
|
||||||
|
std::size_t count;
|
||||||
|
|
||||||
|
constexpr sized_constant_iterator& operator++(void)noexcept{
|
||||||
|
--count;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
constexpr sized_constant_iterator operator++(int)noexcept{
|
||||||
|
sized_constant_iterator other(*this);
|
||||||
|
--count;
|
||||||
|
return other;
|
||||||
|
}
|
||||||
|
constexpr const T& operator*(void)const noexcept{return val;}
|
||||||
|
|
||||||
|
constexpr bool operator==(const sized_constant_iterator& other)const{
|
||||||
|
return count == other.count;
|
||||||
|
}
|
||||||
|
constexpr bool operator!=(const sized_constant_iterator& other)const{
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<class T>
|
||||||
|
sized_constant_iterator(T&&, std::size_t) -> sized_constant_iterator<std::remove_cvref_t<T>>;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user