semf
array.h
Go to the documentation of this file.
1
10#ifndef SEMF_UTILS_CORE_LISTS_ARRAY_H_
11#define SEMF_UTILS_CORE_LISTS_ARRAY_H_
12
13#include <cstddef>
14#include <iterator>
15#include <utility>
16
17namespace semf
18{
24template <typename T>
25class Array
26{
27public:
29 using value_type = T;
31 using size_type = std::size_t;
33 using difference_type = std::ptrdiff_t;
39 using iterator = T*;
41 using const_iterator = const T*;
43 using reverse_iterator = std::reverse_iterator<iterator>;
45 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
46 virtual ~Array() = default;
47
54 virtual reference at(size_type pos) = 0;
61 virtual const_reference at(size_type pos) const = 0;
67 virtual reference operator[](size_type pos) = 0;
73 virtual const_reference operator[](size_type pos) const = 0;
78 virtual reference front() = 0;
83 virtual const_reference front() const = 0;
88 virtual reference back() = 0;
93 virtual const_reference back() const = 0;
100 virtual iterator data() = 0;
107 virtual const T* data() const = 0;
112 virtual iterator begin() = 0;
117 virtual const_iterator begin() const = 0;
122 virtual const_iterator cbegin() const = 0;
128 virtual iterator end() = 0;
134 virtual const_iterator end() const = 0;
140 virtual const_iterator cend() const = 0;
152 virtual const_reverse_iterator rbegin() const = 0;
158 virtual const_reverse_iterator crbegin() const = 0;
164 virtual reverse_iterator rend() = 0;
170 virtual const_reverse_iterator rend() const = 0;
176 virtual const_reverse_iterator crend() const = 0;
181 virtual bool empty() const = 0;
186 virtual size_type size() const = 0;
192 virtual size_type max_size() const = 0;
197 virtual void fill(const T& value) = 0;
204 virtual bool swap(Array<T>& other) = 0;
205};
206} // namespace semf
207#endif // SEMF_UTILS_CORE_LISTS_ARRAY_H_
This is an interface to std::array with the benefit of knowing its size without using a template para...
Definition: array.h:26
T value_type
Definition: array.h:29
std::size_t size_type
Definition: array.h:31
virtual const_reference back() const =0
Returns a reference to the last element in the container. Calling back on an empty container causes u...
T * iterator
Definition: array.h:39
const T * const_iterator
Definition: array.h:41
virtual ~Array()=default
virtual size_type size() const =0
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
virtual void fill(const T &value)=0
Assigns the given value value to all elements in the container.
virtual reverse_iterator rbegin()=0
Returns a reverse iterator to the first element of the reversed array. It corresponds to the last ele...
virtual reference operator[](size_type pos)=0
Returns a reference to the element at specified location pos. No bounds checking is performed.
virtual const_iterator end() const =0
Returns an iterator to the element following the last element of the array. This element acts as a pl...
virtual const_iterator cbegin() const =0
Returns an iterator to the first element of the array. If the array is empty, the returned iterator w...
virtual iterator data()=0
Returns pointer to the underlying array serving as element storage. The pointer is such that range [d...
virtual const_reverse_iterator rend() const =0
Returns a reverse iterator to the element following the last element of the reversed array....
value_type & reference
Definition: array.h:35
virtual const T * data() const =0
Returns pointer to the underlying array serving as element storage. The pointer is such that range [d...
virtual reverse_iterator rend()=0
Returns a reverse iterator to the element following the last element of the reversed array....
virtual iterator end()=0
Returns an iterator to the element following the last element of the array. This element acts as a pl...
std::ptrdiff_t difference_type
Definition: array.h:33
virtual iterator begin()=0
Returns an iterator to the first element of the array. If the array is empty, the returned iterator w...
const value_type & const_reference
Definition: array.h:37
virtual const_reverse_iterator crend() const =0
Returns a reverse iterator to the element following the last element of the reversed array....
virtual const_reference at(size_type pos) const =0
Returns a reference to the element at specified location pos, with bounds checking.
virtual const_iterator begin() const =0
Returns an iterator to the first element of the array. If the array is empty, the returned iterator w...
virtual size_type max_size() const =0
Returns the maximum number of elements the container is able to hold due to system or library impleme...
virtual bool empty() const =0
Checks if the container has no elements, i.e. whether begin() == end().
virtual reference front()=0
Returns a reference to the first element in the container. Calling front on an empty container is und...
virtual const_reference front() const =0
Returns a reference to the first element in the container. Calling front on an empty container is und...
virtual const_reverse_iterator rbegin() const =0
Returns a reverse iterator to the first element of the reversed array. It corresponds to the last ele...
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: array.h:45
virtual const_iterator cend() const =0
Returns an iterator to the element following the last element of the array. This element acts as a pl...
virtual bool swap(Array< T > &other)=0
Exchanges the contents of the container with those of other. Does not cause iterators and references ...
virtual const_reverse_iterator crbegin() const =0
Returns a reverse iterator to the first element of the reversed array. It corresponds to the last ele...
virtual const_reference operator[](size_type pos) const =0
Returns a reference to the element at specified location pos. No bounds checking is performed.
std::reverse_iterator< iterator > reverse_iterator
Definition: array.h:43
virtual reference back()=0
Returns a reference to the last element in the container. Calling back on an empty container causes u...
virtual reference at(size_type pos)=0
Returns a reference to the element at specified location pos, with bounds checking.