20 #ifndef __ARRAY_VIEW_BASE_H__
21 #define __ARRAY_VIEW_BASE_H__
29 #include <boost/iterator/iterator_facade.hpp>
45 class iterator:
public boost::iterator_facade<iterator, T, boost::random_access_traversal_tag> {
48 friend class boost::iterator_core_access;
50 inline T & dereference()
const {
return * elm;}
51 inline bool equal(
iterator const& o)
const {
return elm == o.elm;}
52 inline void increment() {++elm;}
53 inline void decrement() {--elm;}
54 inline void advance(
size_t n) {elm += n;}
55 inline ptrdiff_t distance_to(
iterator const & o)
const {
return o.elm - elm;}
81 iterator
find(
size_t idx)
const throw () {
82 assert(idx <=
size());
83 return iterator(m_start + idx);
91 T &
at(
size_t i)
const throw() {
101 inline bool empty()
const {
return m_end == m_start;}
107 inline size_t size()
const {
return m_end - m_start;}
128 if (
size() != other.
size())
return false;
129 for (
size_t i=0; i <
size(); ++i)
if (
at(i) != other.
at(i))
return false;
140 if (
size() != other.
size())
return true;
141 for (
size_t i=0; i<
size(); ++i)
if (
at(i) != other.
at(i))
return true;
150 inline iterator
begin()
const {
return iterator(m_start);}
157 inline iterator
end()
const {
return iterator(m_end);}
162 inline T &
front()
const {
return *m_start;}
167 inline T &
back()
const {
return *(m_end-1);}
172 #endif //__ARRAY_VIEW_BASE_H__
bool empty() const
Check if the array is empty.
T & at(size_t i) const
Return the element located at the given index.
T & back() const
Return the last element in the array.
Base class for array_view.
bool operator!=(const array_view_base &other) const
Check if the two arrays differ.
T & front() const
Return the first element in the array.
iterator find(size_t idx) const
Return an iterator to the i'th element of the array.
bool operator==(const array_view_base &other) const
Check if the other array has the same elements in the same order as this.
T & operator[](size_t i) const
Return a reference to an array entry.
array_view_base(T *start, T *end)
Pointer constructor.
size_t size() const
Get number of elements in the array.
iterator begin() const
Return an iterator to the beginning of the array.
T value_type
Type of values contained in the array.
iterator end() const
Return an iterator to the end of the array.