TPIE

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

Encapsulation of two pointers from any random access container. More...

#include <tpie/array_view.h>

Inherits tpie::array_view_base< T >.

Public Types

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

Public Member Functions

 array_view (const array_view &o)
 Copy constructor. More...
 
template<typename A >
 array_view (std::vector< T, A > &v)
 std::vector constructor. More...
 
 array_view (tpie::array< T > &v)
 tpie::array constructor. More...
 
 array_view (tpie::internal_vector< T > &v)
 tpie::internal_vector constructor. More...
 
template<typename A >
 array_view (std::vector< T, A > &v, size_t start, size_t end)
 std::vector subsequence. More...
 
 array_view (tpie::array< T > &v, size_t start, size_t end)
 tpie::array subsequence. More...
 
 array_view (T *start, T *end)
 Pointer constructor. More...
 
 array_view (T *start, size_t size)
 Pointer+offset 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< T >

Encapsulation of two pointers from any random access container.

Like std::vector, tpie::array and others, this class has begin(), end() iterators and front(), back() accessors. However, an array_view does not store data, it just stores pointers to data owned by other random access data structures. Passing around array_views, one avoids having the container type as a template parameter in one's code, but the code will still work with any supported random access container.

Definition at line 47 of file array_view.h.

Member Typedef Documentation

◆ value_type

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

Type of values contained in the array.

Definition at line 74 of file array_view_base.h.

Constructor & Destructor Documentation

◆ array_view() [1/8]

template<typename T >
tpie::array_view< T >::array_view ( const array_view< T > &  o)
inline

Copy constructor.

Definition at line 52 of file array_view.h.

52  :
53  array_view_base<T>(o) {}

◆ array_view() [2/8]

template<typename T >
template<typename A >
tpie::array_view< T >::array_view ( std::vector< T, A > &  v)
inline

std::vector constructor.

Definition at line 59 of file array_view.h.

59  :
60  array_view_base<T>(&*(v.begin()), &(*v.end())) {}

◆ array_view() [3/8]

template<typename T >
tpie::array_view< T >::array_view ( tpie::array< T > &  v)
inline

tpie::array constructor.

Definition at line 65 of file array_view.h.

65  :
66  array_view_base<T>(&*(v.begin()), &(*v.end())) {}

◆ array_view() [4/8]

template<typename T >
tpie::array_view< T >::array_view ( tpie::internal_vector< T > &  v)
inline

tpie::internal_vector constructor.

Definition at line 71 of file array_view.h.

71  :
72  array_view_base<T>(&*(v.begin()), &(*v.end())) {}

◆ array_view() [5/8]

template<typename T >
template<typename A >
tpie::array_view< T >::array_view ( std::vector< T, A > &  v,
size_t  start,
size_t  end 
)
inline

std::vector subsequence.

Parameters
vThe std::vector that stores the elements.
startThe index of the first element of the view (such that view.front() == v[start]).
endIndex past the last element of the view (such that view.back() == v[end-1]).

Definition at line 81 of file array_view.h.

81  :
82  array_view_base<T>(&v[start], &v[end]) {}

◆ array_view() [6/8]

template<typename T >
tpie::array_view< T >::array_view ( tpie::array< T > &  v,
size_t  start,
size_t  end 
)
inline

tpie::array subsequence.

Parameters
vThe tpie::array that stores the elements.
startThe index of the first element of the view (such that view.front() == v[start]).
endIndex past the last element of the view (such that view.back() == v[end-1]).

Definition at line 90 of file array_view.h.

90  :
91  array_view_base<T>(&v[start], &v[end]) {}

◆ array_view() [7/8]

template<typename T >
tpie::array_view< T >::array_view ( 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 97 of file array_view.h.

97  :
98  array_view_base<T>(start, end) {}

◆ array_view() [8/8]

template<typename T >
tpie::array_view< T >::array_view ( T *  start,
size_t  size 
)
inline

Pointer+offset constructor.

The array_view will produce the elements in the memory range [start, start+size).

Parameters
startPointer to first element of the array_view.
sizeNumber of elements in the array_view.

Definition at line 106 of file array_view.h.

106  :
107  array_view_base<T>(start, start+size) {}

Member Function Documentation

◆ at()

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

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
inlineinherited

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
inlineinherited

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
inlineinherited

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
inlineinherited

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 (
)
inlineinherited

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
inlineinherited

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
inlineinherited

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
inlineinherited

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
inlineinherited

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::begin
iterator begin()
Return an iterator to the beginning of the array.
Definition: array.h:312
tpie::internal_vector::begin
iterator begin()
Get an iterator to the beginning of the structure.
Definition: internal_vector.h:115
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::end
iterator end()
Return an iterator to the end of the array.
Definition: array.h:326
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
tpie::internal_vector::end
iterator end()
Get an iterator to the end of the structure.
Definition: internal_vector.h:125