TPIE

11a2c2d
tpie::array_view_base< T > Class Template Reference

Base class for array_view. More...

#include <tpie/array_view_base.h>

Inherited by tpie::array_view< T >.

Classes

class  iterator
 

Public Types

typedef T value_type
 Type of values contained in the array. More...
 

Public Member Functions

 array_view_base (T *start, T *end)
 Pointer constructor. More...
 
iterator find (size_t idx) const throw ()
 Return an iterator to the i'th element of the array. More...
 
T & at (size_t i) const throw ()
 Return the element located at the given index. More...
 
bool empty () const
 Check if the array is empty. More...
 
size_t size () const
 Get number of elements in the array. More...
 
T & operator[] (size_t i) const
 Return a reference to an array entry. More...
 
bool operator== (const array_view_base &other) const
 Check if the other array has the same elements in the same order as this. More...
 
bool operator!= (const array_view_base &other) const
 Check if the two arrays differ. More...
 
iterator begin () const
 Return an iterator to the beginning of the array. More...
 
iterator end () const
 Return an iterator to the end of the array. More...
 
T & front () const
 Return the first element in the array. More...
 
T & back () const
 Return the last element in the array. More...
 

Detailed Description

template<typename T>
class tpie::array_view_base< T >

Base class for array_view.

This is needed so that a tpie::array can be constructed from an array_view_base and an array_view can be constructed from a tpie::array.

Definition at line 40 of file array_view_base.h.

Member Typedef Documentation

◆ value_type

template<typename T >
typedef T tpie::array_view_base< T >::value_type

Type of values contained in the array.

Definition at line 74 of file array_view_base.h.

Constructor & Destructor Documentation

◆ array_view_base()

template<typename T >
tpie::array_view_base< T >::array_view_base ( T *  start,
T *  end 
)
inline

Pointer constructor.

The structure will produce the elements in the memory range [start, end).

Parameters
startPointer to first element of the array_view.
endPointer past the last element of the array_view.

Definition at line 69 of file array_view_base.h.

69 : m_start(start), m_end(end) {}

Member Function Documentation

◆ at()

template<typename T >
T& tpie::array_view_base< T >::at ( size_t  i) const
throw (
)
inline

Return the element located at the given index.

Parameters
iThe index of the element returned.

Definition at line 92 of file array_view_base.h.

92  {
93  assert(i < size());
94  return *find(i);
95  }

Referenced by tpie::array_view_base< const T >::operator!=(), tpie::array_view_base< const T >::operator==(), and tpie::array_view_base< const T >::operator[]().

◆ back()

template<typename T >
T& tpie::array_view_base< T >::back ( ) const
inline

Return the last element in the array.

Definition at line 168 of file array_view_base.h.

168 {return *(m_end-1);}

◆ begin()

template<typename T >
iterator tpie::array_view_base< T >::begin ( ) const
inline

Return an iterator to the beginning of the array.

Returns
An iterator to the beginning of the array.

Definition at line 151 of file array_view_base.h.

151 {return iterator(m_start);}

◆ empty()

template<typename T >
bool tpie::array_view_base< T >::empty ( ) const
inline

Check if the array is empty.

Returns
True if and only if size is 0.

Definition at line 102 of file array_view_base.h.

102 {return m_end == m_start;}

◆ end()

template<typename T >
iterator tpie::array_view_base< T >::end ( ) const
inline

Return an iterator to the end of the array.

Returns
An iterator to the end of the array.

Definition at line 158 of file array_view_base.h.

158 {return iterator(m_end);}

◆ find()

template<typename T >
iterator tpie::array_view_base< T >::find ( size_t  idx) const
throw (
)
inline

Return an iterator to the i'th element of the array.

Parameters
idxThe index of the element we want an iterator to.
Returns
An iterator to the i'th element.

Definition at line 82 of file array_view_base.h.

82  {
83  assert(idx <= size());
84  return iterator(m_start + idx);
85  }

Referenced by tpie::array_view_base< const T >::at().

◆ front()

template<typename T >
T& tpie::array_view_base< T >::front ( ) const
inline

Return the first element in the array.

Definition at line 163 of file array_view_base.h.

163 {return *m_start;}

◆ operator!=()

template<typename T >
bool tpie::array_view_base< T >::operator!= ( const array_view_base< T > &  other) const
inline

Check if the two arrays differ.

Parameters
otherThe array to compare against.
Returns
false If they are equal otherwise true.

Definition at line 140 of file array_view_base.h.

140  {
141  if (size() != other.size()) return true;
142  for (size_t i=0; i< size(); ++i) if (at(i) != other.at(i)) return true;
143  return false;
144  }

◆ operator==()

template<typename T >
bool tpie::array_view_base< T >::operator== ( const array_view_base< T > &  other) const
inline

Check if the other array has the same elements in the same order as this.

Parameters
otherThe array to compare against.
Returns
True if they are equal, otherwise false.

Definition at line 128 of file array_view_base.h.

128  {
129  if (size() != other.size()) return false;
130  for (size_t i=0; i < size(); ++i) if (at(i) != other.at(i)) return false;
131  return true;
132  }

◆ operator[]()

template<typename T >
T& tpie::array_view_base< T >::operator[] ( size_t  i) const
inline

Return a reference to an array entry.

Parameters
iThe index of the entry to return.
Returns
Reference to the entry.

Definition at line 116 of file array_view_base.h.

116  {
117  assert(i < size());
118  return at(i);
119  }

◆ size()


The documentation for this class was generated from the following file:
tpie::array_view_base::at
T & at(size_t i) const
Return the element located at the given index.
Definition: array_view_base.h:92
tpie::array_view_base::size
size_t size() const
Get number of elements in the array.
Definition: array_view_base.h:108
tpie::array_view_base::end
iterator end() const
Return an iterator to the end of the array.
Definition: array_view_base.h:158
tpie::array_view_base::find
iterator find(size_t idx) const
Return an iterator to the i'th element of the array.
Definition: array_view_base.h:82