29#ifndef DOXYGEN_SHOULD_SKIP_THIS
48 template<
typename T, std::
size_t N>
54 static constexpr std::size_t Size =
N;
88 StaticSpan(T *data, [[maybe_unused]] std::size_t size) noexcept
101 template<
typename U,
typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
115 template<
typename U,
typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
118 : m_data(array.data())
127 template<
typename U,
typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
130 : m_data(other.getData())
171 return m_data ==
nullptr || Size == 0;
195 return m_data ==
nullptr ? nullptr : m_data + Size;
218 const T *
end() const noexcept {
219 return m_data ==
nullptr ? nullptr : m_data + Size;
230 assert(m_data !=
nullptr && index < Size);
231 return m_data[index];
242 assert(m_data !=
nullptr && index < Size);
243 return m_data[index];
251 template<std::
size_t I>
254 static_assert(
I <
N,
"Out of bounds.");
255 assert(m_data !=
nullptr);
264 template<std::
size_t I>
266 const T&
get() const noexcept {
267 static_assert(
I <
N,
"Out of bounds.");
268 assert(m_data !=
nullptr);
281 assert(b <= e && e <= Size);
282 return Span<T>(m_data + b, e - b);
292 template<std::
size_t B, std::
size_t E>
295 static_assert(
B <=
E &&
E <= Size,
"Out of bounds.");
307 return slice(0, count);
316 template<std::
size_t C>
319 static_assert(
C <= Size,
"Out of bounds.");
320 return slice<0, C>();
331 assert(count <= Size);
332 return slice(Size - count, Size);
341 template<std::
size_t C>
344 static_assert(
C <= Size,
"Out of bounds.");
345 return slice<Size -
C, Size>();
356 assert(count <= Size);
357 return slice(0, Size - count);
366 template<std::
size_t C>
369 static_assert(
C <= Size,
"Out of bounds.");
370 return slice<0, Size -
C>();
381 return slice(count, Size);
390 template<std::
size_t C>
393 static_assert(
C <= Size,
"Out of bounds.");
394 return slice<C, Size>();
449 Span(T *data, std::size_t size)
460 template<
typename U,
typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
462 : m_data(values.data())
463 , m_size(values.size())
472 template<
typename U,
typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value && std::is_const<T>::value>>
473 Span(
const std::vector<U>& values)
474 : m_data(values.data())
475 , m_size(values.size())
484 template<
typename U, std::
size_t N,
typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
486 : m_data(values.data())
487 , m_size(values.size())
498 template<
typename U, std::
size_t N,
typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
510 template<
typename U,
typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
512 : m_data(other.getData())
513 , m_size(other.getSize())
522 template<
typename U, std::
size_t N,
typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
524 : m_data(other.getData())
525 , m_size(other.getSize())
552 constexpr std::size_t
getSize() const noexcept {
584 return m_data + m_size;
594 constexpr const T *
begin() const noexcept {
605 constexpr const T *
end() const noexcept {
606 return m_data + m_size;
618 return m_data[index];
630 return m_data[index];
642 assert(b <= e && e <= m_size);
643 return Span<T>(m_data + b, e - b);
653 template<std::
size_t B, std::
size_t E>
656 static_assert(
B <=
E,
"Out of bounds.");
669 return slice(0, count);
678 template<std::
size_t C>
693 assert(count <= m_size);
694 return slice(m_size - count, m_size);
703 template<std::
size_t C>
718 assert(count <= m_size);
719 return slice(0, m_size - count);
728 template<std::
size_t C>
732 return slice(0, m_size -
C);
743 return slice(count, m_size);
752 template<std::
size_t C>
756 return slice(
C, m_size);
771 template<
typename T, std::
size_t N>
777#ifndef DOXYGEN_SHOULD_SKIP_THIS
A span.
Definition: Span.h:414
constexpr T & operator[](std::size_t index)
Get an element at a given index.
Definition: Span.h:617
constexpr Span< T > firstExcept() const noexcept
Take a span on the first objects.
Definition: Span.h:730
constexpr const T * getData() const noexcept
Get a pointer to the elements.
Definition: Span.h:543
constexpr const T * end() const noexcept
Get an iterator past the last element.
Definition: Span.h:605
constexpr Span(StaticSpan< U, N > other)
Constructor from another static span.
Definition: Span.h:523
constexpr Span< T > slice(std::size_t b, std::size_t e) const noexcept
Take a sub-span.
Definition: Span.h:641
constexpr const T & operator[](std::size_t index) const
Get an element at a given index.
Definition: Span.h:629
constexpr T * end() noexcept
Get an iterator past the last element.
Definition: Span.h:583
constexpr Span(Span< U > other)
Constructor from another span.
Definition: Span.h:511
constexpr Span(T *data, std::size_t size)
Constructor from a pointer and a size.
Definition: Span.h:449
constexpr T * begin() noexcept
Get an iterator to the first element.
Definition: Span.h:572
constexpr T * getData() noexcept
Get a pointer to the elements.
Definition: Span.h:534
constexpr Span(std::nullptr_t)
Null constructor.
Definition: Span.h:436
Span(std::vector< U > &values)
Constructor from a std::vector
Definition: Span.h:461
Span(const std::vector< U > &values)
Constructor from a std::vector
Definition: Span.h:473
constexpr bool isEmpty() const noexcept
Check if the array is empty.
Definition: Span.h:561
Span(std::array< U, N > &values)
Constructor from a std::array
Definition: Span.h:485
constexpr StaticSpan< T, C > last() const noexcept
Take a constant span on the last objects.
Definition: Span.h:705
constexpr const T * begin() const noexcept
Get an iterator to the first element.
Definition: Span.h:594
constexpr Span< T > lastExcept() const noexcept
Take a span on the last objects.
Definition: Span.h:754
constexpr Span()
Default constructor.
Definition: Span.h:424
constexpr Span< T > last(std::size_t count) const noexcept
Take a span on the last objects.
Definition: Span.h:692
constexpr StaticSpan< T, E - B > slice() const noexcept
Take a constant sub-span.
Definition: Span.h:655
constexpr Span(U(&data)[N])
Constructor from a static array.
Definition: Span.h:499
constexpr StaticSpan< T, C > first() const noexcept
Take a constant span on the first objects.
Definition: Span.h:680
constexpr Span< T > first(std::size_t count) const noexcept
Take a span on the first objects.
Definition: Span.h:668
constexpr Span< T > lastExcept(std::size_t count) const noexcept
Take a span on the last objects.
Definition: Span.h:742
constexpr std::size_t getSize() const noexcept
Get the number of elements.
Definition: Span.h:552
constexpr Span< T > firstExcept(std::size_t count) const noexcept
Take a span on the first objects.
Definition: Span.h:717
A static span.
Definition: Span.h:49
constexpr bool isEmpty() const noexcept
Check if the array is empty.
Definition: Span.h:170
constexpr StaticSpan(std::array< U, N > &array) noexcept
Constructor from a std::array
Definition: Span.h:117
constexpr T & get() noexcept
Get an element at a constant index.
Definition: Span.h:253
constexpr StaticSpan< T, C > first() const noexcept
Take a constant span on the first objects.
Definition: Span.h:318
constexpr Span< T > firstExcept(std::size_t count) const noexcept
Take a span on the first objects.
Definition: Span.h:355
constexpr T * getData() noexcept
Get a pointer to the elements.
Definition: Span.h:140
constexpr const T * end() const noexcept
Get an iterator past the last element.
Definition: Span.h:218
constexpr StaticSpan() noexcept
Default constructor.
Definition: Span.h:63
constexpr Span< T > slice(std::size_t b, std::size_t e) const noexcept
Take a sub-span.
Definition: Span.h:280
constexpr T * begin() noexcept
Get an iterator to the first element.
Definition: Span.h:182
constexpr StaticSpan(U(&data)[N]) noexcept
Constructor from a static array.
Definition: Span.h:103
constexpr StaticSpan< T, Size - C > lastExcept() const noexcept
Take a constant span on the last objects.
Definition: Span.h:392
constexpr T * end() noexcept
Get an iterator past the last element.
Definition: Span.h:194
constexpr StaticSpan(T *data, std::size_t size) noexcept
Constructor from a pointer and a size.
Definition: Span.h:88
constexpr Span< T > first(std::size_t count) const noexcept
Take a span on the first objects.
Definition: Span.h:306
constexpr StaticSpan(StaticSpan< U, N > other) noexcept
Constructor from another span.
Definition: Span.h:129
constexpr const T * begin() const noexcept
Get an iterator to the first element.
Definition: Span.h:206
constexpr StaticSpan< T, Size - C > firstExcept() const noexcept
Take a constant span on the first objects.
Definition: Span.h:368
constexpr const T & operator[](std::size_t index) const noexcept
Get an element at a given index.
Definition: Span.h:241
constexpr const T & get() const noexcept
Get an element at a constant index.
Definition: Span.h:266
constexpr Span< T > last(std::size_t count) const noexcept
Take a span on the last objects.
Definition: Span.h:330
constexpr StaticSpan< T, E - B > slice() const noexcept
Take a constant sub-span.
Definition: Span.h:294
constexpr std::size_t getSize() const noexcept
Get the number of elements.
Definition: Span.h:160
constexpr StaticSpan< T, C > last() const noexcept
Take a constant span on the last objects.
Definition: Span.h:343
constexpr StaticSpan(std::nullptr_t) noexcept
Null constructor.
Definition: Span.h:74
constexpr T & operator[](std::size_t index) noexcept
Get an element at a given index.
Definition: Span.h:229
constexpr const T * getData() const noexcept
Get a pointer to the elements.
Definition: Span.h:150
constexpr Span< T > lastExcept(std::size_t count) const noexcept
Take a span on the last objects.
Definition: Span.h:380
The namespace for gf classes.
constexpr Span< T > span(T *data, std::size_t size)
Definition: Span.h:767