mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-06 14:24:09 +00:00
fix slice_array interface
This commit is contained in:
parent
b4da8f5776
commit
f0ec89c423
7 changed files with 206 additions and 60 deletions
|
@ -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>
|
||||
|
@ -32,6 +33,7 @@ namespace sprout {
|
|||
typedef typename valarray_type::difference_type difference_type;
|
||||
typedef typename valarray_type::pointer pointer;
|
||||
typedef sprout::index_iterator<indirect_array const&> iterator;
|
||||
typedef sprout::reverse_iterator<iterator> reverse_iterator;
|
||||
private:
|
||||
typedef sprout::valarray<size_type, M> indexes_type;
|
||||
public:
|
||||
|
@ -160,26 +162,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 indexes_.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_)[indexes_[i]];
|
||||
}
|
||||
SPROUT_CONSTEXPR reference at(size_type i) const {
|
||||
SPROUT_CONSTEXPR reference
|
||||
at(size_type i) const {
|
||||
return arr_->at(indexes_.at(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("indirect_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, std::size_t M>
|
||||
SPROUT_CONSTEXPR_OR_CONST typename sprout::indirect_array<T, N, M>::size_type sprout::indirect_array<T, N, M>::static_size;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue