fix slice_array interface

This commit is contained in:
bolero-MURAKAMI 2016-04-03 18:57:30 +09:00
parent b4da8f5776
commit f0ec89c423
7 changed files with 206 additions and 60 deletions

View file

@ -12,6 +12,7 @@
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/utility/swap.hpp>
#include <sprout/iterator/index_iterator.hpp>
#include <sprout/iterator/reverse_iterator.hpp>
#include <sprout/algorithm/cxx14/copy.hpp>
#include <sprout/algorithm/cxx14/fill.hpp>
#include <sprout/valarray/valarray_fwd.hpp>
@ -58,6 +59,7 @@ namespace sprout {
typedef typename valarray_type::difference_type difference_type;
typedef typename valarray_type::pointer pointer;
typedef sprout::index_iterator<slice_array const&> iterator;
typedef sprout::reverse_iterator<iterator> reverse_iterator;
public:
SPROUT_STATIC_CONSTEXPR size_type static_size = valarray_type::static_size;
private:
@ -183,26 +185,51 @@ namespace sprout {
end() const {
return iterator(*this, size());
}
SPROUT_CONSTEXPR reverse_iterator
rbegin() const {
return reverse_iterator(end());
}
SPROUT_CONSTEXPR reverse_iterator
rend() const {
return reverse_iterator(begin());
}
// capacity:
SPROUT_CONSTEXPR size_type size() const SPROUT_NOEXCEPT {
SPROUT_CONSTEXPR size_type
size() const SPROUT_NOEXCEPT {
return slice_.size();
}
SPROUT_CONSTEXPR bool empty() const SPROUT_NOEXCEPT {
SPROUT_CONSTEXPR bool
empty() const SPROUT_NOEXCEPT {
return size() == 0;
}
// element access:
SPROUT_CONSTEXPR reference operator[](size_type i) const {
SPROUT_CONSTEXPR reference
operator[](size_type i) const {
return (*arr_)[slice_.start() + slice_.stride() * i];
}
SPROUT_CONSTEXPR reference at(size_type i) const {
SPROUT_CONSTEXPR reference
at(size_type i) const {
return arr_->at(slice_.start() + slice_.stride() * i);
}
SPROUT_CONSTEXPR reference front() const {
SPROUT_CONSTEXPR reference
front() const {
return (*this)[0];
}
SPROUT_CONSTEXPR reference back() const {
SPROUT_CONSTEXPR reference
back() const {
return (*this)[size() - 1];
}
// others:
SPROUT_CONSTEXPR iterator
nth(size_type i) const {
return i < size() ? begin() + i
: (throw std::out_of_range("slice_array<>: index out of range"), iterator())
;
}
SPROUT_CONSTEXPR size_type
index_of(iterator p) const SPROUT_NOEXCEPT {
return p - begin();
}
};
template<typename T, std::size_t N>
SPROUT_CONSTEXPR_OR_CONST typename sprout::slice_array<T, N>::size_type sprout::slice_array<T, N>::static_size;