mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
rename ptr_index, ptr_unindex
This commit is contained in:
parent
899bf3fa77
commit
a5e14e71e1
10 changed files with 75 additions and 41 deletions
|
@ -2,6 +2,7 @@
|
|||
#define SPROUT_CONTAINER_CONTAINER_HOLDER_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <stdexcept>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
|
@ -82,6 +83,35 @@ namespace sprout {
|
|||
SPROUT_CONSTEXPR const_param_type get_internal() const {
|
||||
return *container;
|
||||
}
|
||||
// element access:
|
||||
reference operator[](size_type i) {
|
||||
return *sprout::next(begin(), i);
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reference operator[](size_type i) const {
|
||||
return *sprout::next(begin(), i);
|
||||
}
|
||||
reference at(size_type i) {
|
||||
return i < size() ? (*this)[i]
|
||||
: (throw std::out_of_range("container_holder<>: index out of range"), (*this)[i])
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reference at(size_type i) const {
|
||||
return i < size() ? (*this)[i]
|
||||
: (throw std::out_of_range("container_holder<>: index out of range"), (*this)[i])
|
||||
;
|
||||
}
|
||||
reference front() {
|
||||
return *begin();
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reference front() const {
|
||||
return *begin();
|
||||
}
|
||||
reference back() {
|
||||
return *sprout::next(begin(), size() - 1);
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reference back() const {
|
||||
return *sprout::next(begin(), size() - 1);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
|
|
|
@ -30,9 +30,9 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR void const*
|
||||
memchr(void const* s, int c, std::size_t n) {
|
||||
return sprout::detail::memchr_impl(
|
||||
sprout::as_iterator_base(
|
||||
sprout::ptr_unindex(
|
||||
sprout::find(
|
||||
sprout::as_iterator(static_cast<unsigned char const*>(s)), sprout::as_iterator(static_cast<unsigned char const*>(s), n),
|
||||
sprout::ptr_index(static_cast<unsigned char const*>(s)), sprout::ptr_index(static_cast<unsigned char const*>(s), n),
|
||||
static_cast<unsigned char>(c)
|
||||
)
|
||||
),
|
||||
|
@ -43,9 +43,9 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR void*
|
||||
memchr(void* s, int c, std::size_t n) {
|
||||
return sprout::detail::memchr_impl(
|
||||
sprout::as_iterator_base(
|
||||
sprout::ptr_unindex(
|
||||
sprout::find(
|
||||
sprout::as_iterator(static_cast<unsigned char*>(s)), sprout::as_iterator(static_cast<unsigned char*>(s), n),
|
||||
sprout::ptr_index(static_cast<unsigned char*>(s)), sprout::ptr_index(static_cast<unsigned char*>(s), n),
|
||||
static_cast<unsigned char>(c)
|
||||
)
|
||||
),
|
||||
|
|
|
@ -15,8 +15,8 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR int
|
||||
memcmp(void const* s1, void const* s2, std::size_t n) {
|
||||
return sprout::tristate_lexicographical_compare(
|
||||
sprout::as_iterator(static_cast<unsigned char const*>(s1)), sprout::as_iterator(static_cast<unsigned char const*>(s1), n),
|
||||
sprout::as_iterator(static_cast<unsigned char const*>(s2)), sprout::as_iterator(static_cast<unsigned char const*>(s2), n)
|
||||
sprout::ptr_index(static_cast<unsigned char const*>(s1)), sprout::ptr_index(static_cast<unsigned char const*>(s1), n),
|
||||
sprout::ptr_index(static_cast<unsigned char const*>(s2)), sprout::ptr_index(static_cast<unsigned char const*>(s2), n)
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
|
|
@ -70,8 +70,8 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR std::size_t
|
||||
strlen(char const* s, std::size_t n) {
|
||||
return sprout::distance(
|
||||
sprout::as_iterator(s),
|
||||
sprout::find(sprout::as_iterator(s), sprout::as_iterator(s, n), '\0')
|
||||
sprout::ptr_index(s),
|
||||
sprout::find(sprout::ptr_index(s), sprout::ptr_index(s, n), '\0')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -91,8 +91,8 @@ namespace sprout {
|
|||
strlen(Elem* s, std::size_t n) {
|
||||
typedef typename std::decay<Elem>::type type;
|
||||
return sprout::distance(
|
||||
sprout::as_iterator(s),
|
||||
sprout::find(sprout::as_iterator(s), sprout::as_iterator(s, n), type())
|
||||
sprout::ptr_index(s),
|
||||
sprout::find(sprout::ptr_index(s), sprout::ptr_index(s, n), type())
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
|
|
@ -17,8 +17,8 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR int
|
||||
strncmp(char const* s1, char const* s2, std::size_t n) {
|
||||
return sprout::tristate_lexicographical_compare(
|
||||
sprout::as_iterator(s1), sprout::as_iterator(s1, n), '\0',
|
||||
sprout::as_iterator(s2), sprout::as_iterator(s2, n), '\0'
|
||||
sprout::ptr_index(s1), sprout::ptr_index(s1, n), '\0',
|
||||
sprout::ptr_index(s2), sprout::ptr_index(s2, n), '\0'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -30,8 +30,8 @@ namespace sprout {
|
|||
strncmp(Elem* s1, Elem* s2, std::size_t n) {
|
||||
typedef typename std::decay<Elem>::type type;
|
||||
return sprout::tristate_lexicographical_compare(
|
||||
sprout::as_iterator(s1), sprout::as_iterator(s1, n), type(),
|
||||
sprout::as_iterator(s2), sprout::as_iterator(s2, n), type()
|
||||
sprout::ptr_index(s1), sprout::ptr_index(s1, n), type(),
|
||||
sprout::ptr_index(s2), sprout::ptr_index(s2, n), type()
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
|
|
@ -31,9 +31,9 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR wchar_t const*
|
||||
wmemchr(wchar_t const* s, wchar_t c, size_t n) {
|
||||
return sprout::detail::wmemchr_impl(
|
||||
sprout::as_iterator_base(
|
||||
sprout::ptr_unindex(
|
||||
sprout::find(
|
||||
sprout::as_iterator(s), sprout::as_iterator(s, n),
|
||||
sprout::ptr_index(s), sprout::ptr_index(s, n),
|
||||
c
|
||||
)
|
||||
),
|
||||
|
@ -44,9 +44,9 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR wchar_t*
|
||||
wmemchr(wchar_t* s, wchar_t c, size_t n) {
|
||||
return sprout::detail::wmemchr_impl(
|
||||
sprout::as_iterator_base(
|
||||
sprout::ptr_unindex(
|
||||
sprout::find(
|
||||
sprout::as_iterator(s), sprout::as_iterator(s, n),
|
||||
sprout::ptr_index(s), sprout::ptr_index(s, n),
|
||||
c
|
||||
)
|
||||
),
|
||||
|
|
|
@ -16,8 +16,8 @@ namespace sprout {
|
|||
inline SPROUT_CONSTEXPR int
|
||||
wmemcmp(wchar_t const* s1, wchar_t const* s2, std::size_t n) {
|
||||
return sprout::tristate_lexicographical_compare(
|
||||
sprout::as_iterator(s1), sprout::as_iterator(s1, n),
|
||||
sprout::as_iterator(s2), sprout::as_iterator(s2, n)
|
||||
sprout::ptr_index(s1), sprout::ptr_index(s1, n),
|
||||
sprout::ptr_index(s2), sprout::ptr_index(s2, n)
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
|
|
@ -223,41 +223,41 @@ namespace sprout {
|
|||
}
|
||||
|
||||
//
|
||||
// as_iterator
|
||||
// ptr_index
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::ptr_index_iterator<T>
|
||||
as_iterator(T* p) {
|
||||
ptr_index(T* p) {
|
||||
return sprout::make_ptr_index_iterator(p);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR sprout::ptr_index_iterator<T>
|
||||
as_iterator(T* p, typename std::iterator_traits<T*>::difference_type n) {
|
||||
ptr_index(T* p, typename std::iterator_traits<T*>::difference_type n) {
|
||||
return sprout::make_ptr_index_iterator(p, n);
|
||||
}
|
||||
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR Iterator
|
||||
as_iterator(Iterator const& it) {
|
||||
ptr_index(Iterator const& it) {
|
||||
return it;
|
||||
}
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR Iterator
|
||||
as_iterator(Iterator const& it, typename std::iterator_traits<Iterator>::difference_type n) {
|
||||
ptr_index(Iterator const& it, typename std::iterator_traits<Iterator>::difference_type n) {
|
||||
return sprout::next(it, n);
|
||||
}
|
||||
|
||||
//
|
||||
// as_iterator_base
|
||||
// ptr_unindex
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR typename sprout::ptr_index_iterator<T>::pointer
|
||||
as_iterator_base(sprout::ptr_index_iterator<T> const& it) {
|
||||
ptr_unindex(sprout::ptr_index_iterator<T> const& it) {
|
||||
return it.ptr();
|
||||
}
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR Iterator
|
||||
as_iterator_base(Iterator const& it) {
|
||||
ptr_unindex(Iterator const& it) {
|
||||
return it;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,8 +74,8 @@ namespace sprout {
|
|||
}
|
||||
static SPROUT_CONSTEXPR int compare(char_type const* s1, char_type const* s2, std::size_t n) {
|
||||
return sprout::tristate_lexicographical_compare(
|
||||
sprout::as_iterator(s1), sprout::as_iterator(s1, n), char_type(),
|
||||
sprout::as_iterator(s2), sprout::as_iterator(s2, n), char_type(),
|
||||
sprout::ptr_index(s1), sprout::ptr_index(s1, n), char_type(),
|
||||
sprout::ptr_index(s2), sprout::ptr_index(s2, n), char_type(),
|
||||
sprout::detail::char_traits_lt<char_traits>()
|
||||
);
|
||||
}
|
||||
|
@ -84,9 +84,9 @@ namespace sprout {
|
|||
}
|
||||
static SPROUT_CONSTEXPR char_type const* find(char_type const* s, std::size_t n, char_type const& a) {
|
||||
return find_impl(
|
||||
sprout::as_iterator_base(
|
||||
sprout::ptr_unindex(
|
||||
sprout::find_if(
|
||||
sprout::as_iterator(s), sprout::as_iterator(s, n),
|
||||
sprout::ptr_index(s), sprout::ptr_index(s, n),
|
||||
sprout::bind2nd(sprout::detail::char_traits_eq<char_traits>(), a)
|
||||
)
|
||||
),
|
||||
|
@ -121,7 +121,7 @@ namespace sprout {
|
|||
template<typename ConstIterator>
|
||||
static SPROUT_CONSTEXPR int compare(char_type const* s1, ConstIterator s2, std::size_t n) {
|
||||
return sprout::tristate_lexicographical_compare(
|
||||
sprout::as_iterator(s1), sprout::as_iterator(s1, n), char_type(),
|
||||
sprout::ptr_index(s1), sprout::ptr_index(s1, n), char_type(),
|
||||
s2, s2 + n, char_type(),
|
||||
sprout::detail::char_traits_lt<char_traits>()
|
||||
);
|
||||
|
@ -130,7 +130,7 @@ namespace sprout {
|
|||
static SPROUT_CONSTEXPR int compare(ConstIterator s1, char_type const* s2, std::size_t n) {
|
||||
return sprout::tristate_lexicographical_compare(
|
||||
s1, s1 + n, char_type(),
|
||||
sprout::as_iterator(s2), sprout::as_iterator(s2, n), char_type(),
|
||||
sprout::ptr_index(s2), sprout::ptr_index(s2, n), char_type(),
|
||||
sprout::detail::char_traits_lt<char_traits>()
|
||||
);
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ namespace sprout {
|
|||
}
|
||||
template<typename ConstIterator>
|
||||
static SPROUT_CONSTEXPR ConstIterator find(ConstIterator s, std::size_t n, char_type const& a) {
|
||||
return sprout::as_iterator_base(
|
||||
return sprout::ptr_unindex(
|
||||
sprout::find_if(
|
||||
s, s + n,
|
||||
sprout::bind2nd(sprout::detail::char_traits_eq<char_traits>(), a)
|
||||
|
@ -190,9 +190,9 @@ namespace sprout {
|
|||
return sprout::strlen(s, n);
|
||||
}
|
||||
static SPROUT_CONSTEXPR char_type const* find(char_type const* s, std::size_t n, char_type const& a) {
|
||||
return sprout::as_iterator_base(
|
||||
return sprout::ptr_unindex(
|
||||
sprout::find_if(
|
||||
sprout::as_iterator(s), sprout::as_iterator(s, n),
|
||||
sprout::ptr_index(s), sprout::ptr_index(s, n),
|
||||
sprout::bind2nd(sprout::detail::char_traits_eq<traits_type>(), a)
|
||||
)
|
||||
);
|
||||
|
|
|
@ -284,14 +284,12 @@ namespace sprout {
|
|||
return *sprout::next(sprout::begin(get_array()), to_first_ + i);
|
||||
}
|
||||
reference at(size_type i) {
|
||||
return i < size()
|
||||
? *sprout::next(sprout::begin(get_array()), to_first_ + i)
|
||||
return i < size() ? *sprout::next(sprout::begin(get_array()), to_first_ + i)
|
||||
: (throw std::out_of_range("sub_array<>: index out of range"), *sprout::next(sprout::begin(get_array()), to_first_ + i))
|
||||
;
|
||||
}
|
||||
SPROUT_CONSTEXPR const_reference at(size_type i) const {
|
||||
return i < size()
|
||||
? *sprout::next(sprout::begin(get_array()), to_first_ + i)
|
||||
return i < size() ? *sprout::next(sprout::begin(get_array()), to_first_ + i)
|
||||
: (throw std::out_of_range("sub_array<>: index out of range"), *sprout::next(sprout::begin(get_array()), to_first_ + i))
|
||||
;
|
||||
}
|
||||
|
@ -359,6 +357,12 @@ namespace sprout {
|
|||
SPROUT_CONSTEXPR difference_type to_last() const {
|
||||
return to_last_;
|
||||
}
|
||||
SPROUT_CONSTEXPR difference_type from_begin() const {
|
||||
return to_first_;
|
||||
}
|
||||
SPROUT_CONSTEXPR difference_type from_end() const {
|
||||
return to_last_ - sprout::size(get_array());
|
||||
}
|
||||
};
|
||||
template<typename Container>
|
||||
SPROUT_CONSTEXPR_OR_CONST typename sprout::sub_array<Container>::size_type sprout::sub_array<Container>::enumerable_size;
|
||||
|
|
Loading…
Reference in a new issue