8#ifndef SEN_CORE_BASE_SPAN_H
9#define SEN_CORE_BASE_SPAN_H
52 ~
Span() noexcept = default;
56 template <typename U,
std::enable_if_t<
std::is_convertible_v<U*, T*>,
int> = 0>
58 : data_(other.data_), size_(other.size_)
67 template <std::
size_t n>
68 constexpr Span(std::array<value_type, n>& array)
noexcept: data_(array.data()), size_(array.size())
73 template <std::
size_t n>
74 constexpr Span(
const std::array<value_type, n>& array)
noexcept: data_(array.data()), size_(array.size())
79 template <
typename U, std::
size_t n, std::enable_if_t<std::is_convertible_v<U*, T*>,
int> = 0>
80 constexpr Span(std::array<U, n>& array)
noexcept
81 : data_(array.data()), size_(array.size())
86 template <
typename U, std::
size_t n, std::enable_if_t<std::is_convertible_v<U*, T*>,
int> = 0>
87 constexpr Span(
const std::array<U, n>& array)
noexcept
88 : data_(array.data()), size_(array.size())
93 constexpr Span(std::vector<value_type>& vector)
noexcept: data_(vector.data()), size_(vector.size()) {}
96 constexpr Span(
const std::vector<value_type>& vector)
noexcept: data_(vector.data()), size_(vector.size()) {}
99 template <
typename U, std::enable_if_t<std::is_convertible_v<U*, T*>,
int> = 0>
100 constexpr Span(std::vector<U>& vector)
noexcept
101 : data_(vector.data()), size_(vector.size())
106 template <
typename U, std::enable_if_t<std::is_convertible_v<U*, T*>,
int> = 0>
107 constexpr Span(
const std::vector<U>& vector)
noexcept
108 : data_(vector.data()), size_(vector.size())
133 [[nodiscard]] constexpr
std::
size_t size() const noexcept {
return size_; }
136 [[nodiscard]]
constexpr bool empty() const noexcept {
return size_ == 0; }
153 [[nodiscard]]
constexpr pointer data() const noexcept {
return data_; }
186 return lhs.size() == rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin());
192 return !(lhs == rhs);
207template <
typename T, std::
size_t n>
221template <typename Iterator, typename T = typename std::iterator_traits<Iterator>::value_type>
224 return makeSpan(&*first,
static_cast<std::size_t
>(std::distance(first, last)));
235template <
typename T, std::
size_t s>
255template <
typename T, std::
size_t n>
263template <typename Iterator, typename T = typename std::iterator_traits<Iterator>::value_type>
266 return makeConstSpan(&*first,
static_cast<std::size_t
>(std::distance(first, last)));
279template <
typename T, std::
size_t s>
295 return {
data(), count};
302 return {
data() + (
size() - count), count};
309 return {
data() + offset,
size() - offset};
317 return {
data() + offset, count};
324 return *(
data() + i);
The following macros implement a replacement of assert that is connected to the overall fault handlin...
Contiguous view of elements of type T. Inspired by http://www.open-std.org/jtc1/sc22/wg21/docs/papers...
Definition span.h:34
reference operator[](index_type i) const noexcept
Gets the element at index i. Complexity: constant.
Definition span.h:321
constexpr bool empty() const noexcept
Definition span.h:136
Span last(index_type count) const noexcept
Returns a new Span over the last count elements of *this.
Definition span.h:299
std::remove_cv_t< T > value_type
Definition span.h:40
const T * const_iterator
Definition span.h:46
T & reference
Definition span.h:44
T element_type
Definition span.h:39
std::reverse_iterator< iterator > reverse_iterator
Definition span.h:47
constexpr const_iterator cbegin() const noexcept
Returns a const iterator to the first element of the vector. If the Span is empty,...
Definition span.h:168
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition span.h:48
ptrdiff_t difference_type
Definition span.h:42
Span first(index_type count) const noexcept
Returns a new span over the first count elements of *this.
Definition span.h:292
T * iterator
Definition span.h:45
constexpr pointer data() const noexcept
Direct access to the underlying storage. Complexity: constant.
Definition span.h:153
constexpr Span(std::array< value_type, n > &array) noexcept
Builds a Span out of an array.
Definition span.h:68
constexpr iterator begin() const noexcept
Returns an iterator to the first element of the Span. If the vector is empty, the returned iterator w...
Definition span.h:159
constexpr Span(const std::array< U, n > &array) noexcept
Builds a Span out of a const array.
Definition span.h:87
constexpr iterator end() const noexcept
Iterator to the element following the last element. Complexity: constant. NOLINTNEXTLINE(cppcoreguide...
Definition span.h:163
constexpr Span(const std::array< value_type, n > &array) noexcept
Builds a Span out of an array.
Definition span.h:74
constexpr Span(const std::vector< U > &vector) noexcept
Builds a Span out of a const compatible vector.
Definition span.h:107
constexpr std::size_t size() const noexcept
Definition span.h:133
constexpr Span(pointer ptr, index_type count) noexcept
Builds a Span out of a pointer and an element count.
Definition span.h:64
constexpr Span(std::vector< U > &vector) noexcept
Builds a Span out of a compatible vector.
Definition span.h:100
constexpr Span(std::vector< value_type > &vector) noexcept
Builds a Span out of a vector. NOLINTNEXTLINE(hicpp-explicit-conversions).
Definition span.h:93
T * pointer
Definition span.h:43
constexpr Span(std::array< U, n > &array) noexcept
Builds a Span out of an array.
Definition span.h:80
Span subspan(index_type offset=0) const noexcept
Returns a new Span over the elements of *this beginning at offset and extending for size() - offset e...
Definition span.h:306
constexpr const_iterator cend() const noexcept
Constant iterator to the element following the last element. Complexity: constant....
Definition span.h:172
constexpr Span(const std::vector< value_type > &vector) noexcept
Builds a Span out of a vector. NOLINTNEXTLINE(hicpp-explicit-conversions).
Definition span.h:96
std::size_t index_type
Definition span.h:41
#define SEN_EXPECT(expr)
Checks a pre-condition of a procedure (function parameter for example). NOLINTNEXTLINE.
Definition assert.h:36
constexpr bool operator!=(const Span< T > &lhs, const Span< T > &rhs) noexcept
Definition span.h:190
constexpr bool operator==(const Span< T > &lhs, const Span< T > &rhs) noexcept
Definition span.h:184
constexpr Span< T > makeSpan(T *ptr, std::size_t size) noexcept
Takes in a type that can be passed to a contiguous range and returns a Span.
Definition span.h:201
constexpr Span< const T > makeConstSpan(const T *ptr, std::size_t size) noexcept
Takes in a type that can be passed to a contiguous range and returns a Span. The element types will b...
Definition span.h:248