semf
semf::Array< T > Class Template Referenceabstract

This is an interface to std::array with the benefit of knowing its size without using a template parameter so it can be used easier in object oriented code. More...

#include <array.h>

Collaboration diagram for semf::Array< T >:
Collaboration graph

Public Types

using value_type = T
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 
using reference = value_type &
 
using const_reference = const value_type &
 
using iterator = T *
 
using const_iterator = const T *
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 

Public Member Functions

virtual ~Array ()=default
 
virtual reference at (size_type pos)=0
 Returns a reference to the element at specified location pos, with bounds checking. More...
 
virtual const_reference at (size_type pos) const =0
 Returns a reference to the element at specified location pos, with bounds checking. More...
 
virtual reference operator[] (size_type pos)=0
 Returns a reference to the element at specified location pos. No bounds checking is performed. More...
 
virtual const_reference operator[] (size_type pos) const =0
 Returns a reference to the element at specified location pos. No bounds checking is performed. More...
 
virtual reference front ()=0
 Returns a reference to the first element in the container. Calling front on an empty container is undefined. More...
 
virtual const_reference front () const =0
 Returns a reference to the first element in the container. Calling front on an empty container is undefined. More...
 
virtual reference back ()=0
 Returns a reference to the last element in the container. Calling back on an empty container causes undefined behavior. More...
 
virtual const_reference back () const =0
 Returns a reference to the last element in the container. Calling back on an empty container causes undefined behavior. More...
 
virtual iterator data ()=0
 Returns pointer to the underlying array serving as element storage. The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty ( data() is not dereferenceable in that case). More...
 
virtual const T * data () const =0
 Returns pointer to the underlying array serving as element storage. The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty ( data() is not dereferenceable in that case). More...
 
virtual iterator begin ()=0
 Returns an iterator to the first element of the array. If the array is empty, the returned iterator will be equal to end(). More...
 
virtual const_iterator begin () const =0
 Returns an iterator to the first element of the array. If the array is empty, the returned iterator will be equal to end(). More...
 
virtual const_iterator cbegin () const =0
 Returns an iterator to the first element of the array. If the array is empty, the returned iterator will be equal to end(). More...
 
virtual iterator end ()=0
 Returns an iterator to the element following the last element of the array. This element acts as a placeholder; attempting to access it results in undefined behavior. More...
 
virtual const_iterator end () const =0
 Returns an iterator to the element following the last element of the array. This element acts as a placeholder; attempting to access it results in undefined behavior. More...
 
virtual const_iterator cend () const =0
 Returns an iterator to the element following the last element of the array. This element acts as a placeholder; attempting to access it results in undefined behavior. More...
 
virtual reverse_iterator rbegin ()=0
 Returns a reverse iterator to the first element of the reversed array. It corresponds to the last element of the non-reversed array. If the array is empty, the returned iterator is equal to rend(). More...
 
virtual const_reverse_iterator rbegin () const =0
 Returns a reverse iterator to the first element of the reversed array. It corresponds to the last element of the non-reversed array. If the array is empty, the returned iterator is equal to rend(). More...
 
virtual const_reverse_iterator crbegin () const =0
 Returns a reverse iterator to the first element of the reversed array. It corresponds to the last element of the non-reversed array. If the array is empty, the returned iterator is equal to rend(). More...
 
virtual reverse_iterator rend ()=0
 Returns a reverse iterator to the element following the last element of the reversed array. It corresponds to the element preceding the first element of the non-reversed array. This element acts as a placeholder, attempting to access it results in undefined behavior. More...
 
virtual const_reverse_iterator rend () const =0
 Returns a reverse iterator to the element following the last element of the reversed array. It corresponds to the element preceding the first element of the non-reversed array. This element acts as a placeholder, attempting to access it results in undefined behavior. More...
 
virtual const_reverse_iterator crend () const =0
 Returns a reverse iterator to the element following the last element of the reversed array. It corresponds to the element preceding the first element of the non-reversed array. This element acts as a placeholder, attempting to access it results in undefined behavior. More...
 
virtual bool empty () const =0
 Checks if the container has no elements, i.e. whether begin() == end(). More...
 
virtual size_type size () const =0
 Returns the number of elements in the container, i.e. std::distance(begin(), end()). More...
 
virtual size_type max_size () const =0
 Returns the maximum number of elements the container is able to hold due to system or library implementation limitations, i.e. std::distance(begin(), end()) for the largest container. More...
 
virtual void fill (const T &value)=0
 Assigns the given value value to all elements in the container. More...
 
virtual bool swap (Array< T > &other)=0
 Exchanges the contents of the container with those of other. Does not cause iterators and references to associate with the other container. In order to succeed both array must be equally sized. More...
 

Detailed Description

template<typename T>
class semf::Array< T >

This is an interface to std::array with the benefit of knowing its size without using a template parameter so it can be used easier in object oriented code.

Template Parameters
TElement type of the array.

Definition at line 25 of file array.h.

Member Typedef Documentation

◆ const_iterator

template<typename T >
using semf::Array< T >::const_iterator = const T*

Const iterator type.

Definition at line 41 of file array.h.

◆ const_reference

template<typename T >
using semf::Array< T >::const_reference = const value_type&

Const reference type.

Definition at line 37 of file array.h.

◆ const_reverse_iterator

template<typename T >
using semf::Array< T >::const_reverse_iterator = std::reverse_iterator<const_iterator>

Const reverse iterator type.

Definition at line 45 of file array.h.

◆ difference_type

template<typename T >
using semf::Array< T >::difference_type = std::ptrdiff_t

Difference type.

Definition at line 33 of file array.h.

◆ iterator

template<typename T >
using semf::Array< T >::iterator = T*

Iterator type.

Definition at line 39 of file array.h.

◆ reference

template<typename T >
using semf::Array< T >::reference = value_type&

Reference type.

Definition at line 35 of file array.h.

◆ reverse_iterator

template<typename T >
using semf::Array< T >::reverse_iterator = std::reverse_iterator<iterator>

Reverse iterator type.

Definition at line 43 of file array.h.

◆ size_type

template<typename T >
using semf::Array< T >::size_type = std::size_t

Size type.

Definition at line 31 of file array.h.

◆ value_type

template<typename T >
using semf::Array< T >::value_type = T

Value type.

Definition at line 29 of file array.h.

Constructor & Destructor Documentation

◆ ~Array()

template<typename T >
virtual semf::Array< T >::~Array ( )
virtualdefault

Member Function Documentation

◆ at() [1/2]

template<typename T >
virtual const_reference semf::Array< T >::at ( size_type  pos) const
pure virtual

Returns a reference to the element at specified location pos, with bounds checking.

Parameters
posPosition of the element to return.
Returns
Reference to the requested element.
Exceptions
std::out_of_rangeIf !(pos < size()).

◆ at() [2/2]

template<typename T >
virtual reference semf::Array< T >::at ( size_type  pos)
pure virtual

Returns a reference to the element at specified location pos, with bounds checking.

Parameters
posPosition of the element to return.
Returns
Reference to the requested element.
Exceptions
std::out_of_rangeIf !(pos < size()).

◆ back() [1/2]

template<typename T >
virtual const_reference semf::Array< T >::back ( ) const
pure virtual

Returns a reference to the last element in the container. Calling back on an empty container causes undefined behavior.

Returns
Reference to the last element.

◆ back() [2/2]

template<typename T >
virtual reference semf::Array< T >::back ( )
pure virtual

Returns a reference to the last element in the container. Calling back on an empty container causes undefined behavior.

Returns
Reference to the last element.

◆ begin() [1/2]

template<typename T >
virtual const_iterator semf::Array< T >::begin ( ) const
pure virtual

Returns an iterator to the first element of the array. If the array is empty, the returned iterator will be equal to end().

Returns
Iterator to the first element.

◆ begin() [2/2]

template<typename T >
virtual iterator semf::Array< T >::begin ( )
pure virtual

Returns an iterator to the first element of the array. If the array is empty, the returned iterator will be equal to end().

Returns
Iterator to the first element.

◆ cbegin()

template<typename T >
virtual const_iterator semf::Array< T >::cbegin ( ) const
pure virtual

Returns an iterator to the first element of the array. If the array is empty, the returned iterator will be equal to end().

Returns
Iterator to the first element.

◆ cend()

template<typename T >
virtual const_iterator semf::Array< T >::cend ( ) const
pure virtual

Returns an iterator to the element following the last element of the array. This element acts as a placeholder; attempting to access it results in undefined behavior.

Returns
Iterator to the element following the last element.

◆ crbegin()

template<typename T >
virtual const_reverse_iterator semf::Array< T >::crbegin ( ) const
pure virtual

Returns a reverse iterator to the first element of the reversed array. It corresponds to the last element of the non-reversed array. If the array is empty, the returned iterator is equal to rend().

Returns
Reverse iterator to the first element.

◆ crend()

template<typename T >
virtual const_reverse_iterator semf::Array< T >::crend ( ) const
pure virtual

Returns a reverse iterator to the element following the last element of the reversed array. It corresponds to the element preceding the first element of the non-reversed array. This element acts as a placeholder, attempting to access it results in undefined behavior.

Returns
Reverse iterator to the element following the last element.

◆ data() [1/2]

template<typename T >
virtual const T * semf::Array< T >::data ( ) const
pure virtual

Returns pointer to the underlying array serving as element storage. The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty ( data() is not dereferenceable in that case).

Returns
Pointer to the underlying element storage. For non-empty containers, the returned pointer compares equal to the address of the first element.
Note
If size() is 0, data() may or may not return a null pointer.

◆ data() [2/2]

template<typename T >
virtual iterator semf::Array< T >::data ( )
pure virtual

Returns pointer to the underlying array serving as element storage. The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty ( data() is not dereferenceable in that case).

Returns
Pointer to the underlying element storage. For non-empty containers, the returned pointer compares equal to the address of the first element.
Note
If size() is 0, data() may or may not return a null pointer.

◆ empty()

template<typename T >
virtual bool semf::Array< T >::empty ( ) const
pure virtual

Checks if the container has no elements, i.e. whether begin() == end().

Returns
true if the container is empty, false otherwise.

◆ end() [1/2]

template<typename T >
virtual const_iterator semf::Array< T >::end ( ) const
pure virtual

Returns an iterator to the element following the last element of the array. This element acts as a placeholder; attempting to access it results in undefined behavior.

Returns
Iterator to the element following the last element.

◆ end() [2/2]

template<typename T >
virtual iterator semf::Array< T >::end ( )
pure virtual

Returns an iterator to the element following the last element of the array. This element acts as a placeholder; attempting to access it results in undefined behavior.

Returns
Iterator to the element following the last element.

◆ fill()

template<typename T >
virtual void semf::Array< T >::fill ( const T &  value)
pure virtual

Assigns the given value value to all elements in the container.

Parameters
valueThe value to assign to the elements.

◆ front() [1/2]

template<typename T >
virtual const_reference semf::Array< T >::front ( ) const
pure virtual

Returns a reference to the first element in the container. Calling front on an empty container is undefined.

Returns
Reference to the first element.

◆ front() [2/2]

template<typename T >
virtual reference semf::Array< T >::front ( )
pure virtual

Returns a reference to the first element in the container. Calling front on an empty container is undefined.

Returns
Reference to the first element.

◆ max_size()

template<typename T >
virtual size_type semf::Array< T >::max_size ( ) const
pure virtual

Returns the maximum number of elements the container is able to hold due to system or library implementation limitations, i.e. std::distance(begin(), end()) for the largest container.

Returns
Maximum number of elements.

◆ operator[]() [1/2]

template<typename T >
virtual const_reference semf::Array< T >::operator[] ( size_type  pos) const
pure virtual

Returns a reference to the element at specified location pos. No bounds checking is performed.

Parameters
posPosition of the element to return.
Returns
Reference to the requested element.

◆ operator[]() [2/2]

template<typename T >
virtual reference semf::Array< T >::operator[] ( size_type  pos)
pure virtual

Returns a reference to the element at specified location pos. No bounds checking is performed.

Parameters
posPosition of the element to return.
Returns
Reference to the requested element.

◆ rbegin() [1/2]

template<typename T >
virtual const_reverse_iterator semf::Array< T >::rbegin ( ) const
pure virtual

Returns a reverse iterator to the first element of the reversed array. It corresponds to the last element of the non-reversed array. If the array is empty, the returned iterator is equal to rend().

Returns
Reverse iterator to the first element.

◆ rbegin() [2/2]

template<typename T >
virtual reverse_iterator semf::Array< T >::rbegin ( )
pure virtual

Returns a reverse iterator to the first element of the reversed array. It corresponds to the last element of the non-reversed array. If the array is empty, the returned iterator is equal to rend().

Returns
Reverse iterator to the first element.

◆ rend() [1/2]

template<typename T >
virtual const_reverse_iterator semf::Array< T >::rend ( ) const
pure virtual

Returns a reverse iterator to the element following the last element of the reversed array. It corresponds to the element preceding the first element of the non-reversed array. This element acts as a placeholder, attempting to access it results in undefined behavior.

Returns
Reverse iterator to the element following the last element.

◆ rend() [2/2]

template<typename T >
virtual reverse_iterator semf::Array< T >::rend ( )
pure virtual

Returns a reverse iterator to the element following the last element of the reversed array. It corresponds to the element preceding the first element of the non-reversed array. This element acts as a placeholder, attempting to access it results in undefined behavior.

Returns
Reverse iterator to the element following the last element.

◆ size()

template<typename T >
virtual size_type semf::Array< T >::size ( ) const
pure virtual

Returns the number of elements in the container, i.e. std::distance(begin(), end()).

Returns
The number of elements in the container.

◆ swap()

template<typename T >
virtual bool semf::Array< T >::swap ( Array< T > &  other)
pure virtual

Exchanges the contents of the container with those of other. Does not cause iterators and references to associate with the other container. In order to succeed both array must be equally sized.

Parameters
otherContainer to exchange the contents with.
Returns
true if successful, otherwise false.