31 #ifndef DOXYGEN_SHOULD_SKIP_THIS 50 template<
typename T, std::
size_t N>
56 static constexpr std::size_t Size =
N;
104 template<typename U, typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
118 template<typename U, typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
121 : m_data(array.data())
130 template<typename U, typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
133 : m_data(other.getData())
174 return m_data ==
nullptr || Size == 0;
198 return m_data ==
nullptr ? nullptr : m_data + Size;
221 const T *
end() const noexcept {
222 return m_data ==
nullptr ? nullptr : m_data + Size;
233 assert(m_data !=
nullptr && index < Size);
234 return m_data[index];
245 assert(m_data !=
nullptr && index < Size);
246 return m_data[index];
254 template<std::
size_t I>
257 static_assert(
I <
N,
"Out of bounds.");
258 assert(m_data !=
nullptr);
267 template<std::
size_t I>
269 const T&
get()
const noexcept {
270 static_assert(
I <
N,
"Out of bounds.");
271 assert(m_data !=
nullptr);
284 assert(b <= e && e <= Size);
285 return Span<T>(m_data + b, e - b);
295 template<std::
size_t B, std::
size_t E>
298 static_assert(
B <=
E &&
E <= Size,
"Out of bounds.");
310 return slice(0, count);
319 template<std::
size_t C>
322 static_assert(
C <= Size,
"Out of bounds.");
323 return slice<0, C>();
334 assert(count <= Size);
335 return slice(Size - count, Size);
344 template<std::
size_t C>
347 static_assert(
C <= Size,
"Out of bounds.");
348 return slice<Size -
C, Size>();
359 assert(count <= Size);
360 return slice(0, Size - count);
369 template<std::
size_t C>
372 static_assert(
C <= Size,
"Out of bounds.");
373 return slice<0, Size -
C>();
384 return slice(count, Size);
393 template<std::
size_t C>
396 static_assert(
C <= Size,
"Out of bounds.");
397 return slice<C, Size>();
463 template<typename U, typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
465 : m_data(values.data())
466 , m_size(values.size())
475 template<typename U, typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value && std::is_const<T>::value>>
476 Span(
const std::vector<U>& values)
477 : m_data(values.data())
478 , m_size(values.size())
487 template<typename U, std::size_t N, typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
489 : m_data(values.data())
490 , m_size(values.size())
501 template<typename U, std::size_t N, typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
513 template<typename U, typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
515 : m_data(other.getData())
516 , m_size(other.getSize())
525 template<typename U, std::size_t N, typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
527 : m_data(other.getData())
528 , m_size(other.getSize())
555 constexpr std::size_t
getSize() const noexcept {
587 return m_data + m_size;
597 constexpr
const T *
begin() const noexcept {
608 constexpr
const T *
end() const noexcept {
609 return m_data + m_size;
621 return m_data[index];
633 return m_data[index];
645 assert(b <= e && e <= m_size);
646 return Span<T>(m_data + b, e - b);
656 template<std::
size_t B, std::
size_t E>
659 static_assert(
B <=
E,
"Out of bounds.");
672 return slice(0, count);
681 template<std::
size_t C>
696 assert(count <= m_size);
697 return slice(m_size - count, m_size);
706 template<std::
size_t C>
721 assert(count <= m_size);
722 return slice(0, m_size - count);
731 template<std::
size_t C>
735 return slice(0, m_size -
C);
746 return slice(count, m_size);
755 template<std::
size_t C>
759 return slice(
C, m_size);
774 template<
typename T, std::
size_t N>
780 #ifndef DOXYGEN_SHOULD_SKIP_THIS constexpr Span< T > first(std::size_t count) const noexcept
Take a span on the first objects.
Definition: Span.h:309
constexpr T * begin() noexcept
Get an iterator to the first element.
Definition: Span.h:185
constexpr Span< T > lastExcept(std::size_t count) const noexcept
Take a span on the last objects.
Definition: Span.h:383
constexpr T * end() noexcept
Get an iterator past the last element.
Definition: Span.h:586
constexpr StaticSpan(T *data, std::size_t size) noexcept
Constructor from a pointer and a size.
Definition: Span.h:90
constexpr Span< T > firstExcept(std::size_t count) const noexcept
Take a span on the first objects.
Definition: Span.h:358
constexpr StaticSpan< T, C > first() const noexcept
Take a constant span on the first objects.
Definition: Span.h:321
constexpr StaticSpan< T, E - B > slice() const noexcept
Take a constant sub-span.
Definition: Span.h:658
constexpr const T * begin() const noexcept
Get an iterator to the first element.
Definition: Span.h:209
constexpr T * end() noexcept
Get an iterator past the last element.
Definition: Span.h:197
Span(const std::vector< U > &values)
Constructor from a std::vector
Definition: Span.h:476
constexpr Span< T > firstExcept() const noexcept
Take a span on the first objects.
Definition: Span.h:733
Span(std::array< U, N > &values)
Constructor from a std::array
Definition: Span.h:488
constexpr Span< T > first(std::size_t count) const noexcept
Take a span on the first objects.
Definition: Span.h:671
constexpr T & operator[](std::size_t index) noexcept
Get an element at a given index.
Definition: Span.h:232
constexpr Span< T > slice(std::size_t b, std::size_t e) const noexcept
Take a sub-span.
Definition: Span.h:283
A span.
Definition: Span.h:36
constexpr StaticSpan< T, C > last() const noexcept
Take a constant span on the last objects.
Definition: Span.h:346
constexpr T & operator[](std::size_t index)
Get an element at a given index.
Definition: Span.h:620
constexpr const T * begin() const noexcept
Get an iterator to the first element.
Definition: Span.h:597
A static span.
Definition: Span.h:51
constexpr StaticSpan< T, Size - C > firstExcept() const noexcept
Take a constant span on the first objects.
Definition: Span.h:371
constexpr Span< T > span(T *data, std::size_t size)
Definition: Span.h:770
constexpr const T * end() const noexcept
Get an iterator past the last element.
Definition: Span.h:221
constexpr bool isEmpty() const noexcept
Check if the array is empty.
Definition: Span.h:564
constexpr T * begin() noexcept
Get an iterator to the first element.
Definition: Span.h:575
constexpr StaticSpan(U(&data)[N]) noexcept
Constructor from a static array.
Definition: Span.h:106
constexpr Span< T > last(std::size_t count) const noexcept
Take a span on the last objects.
Definition: Span.h:695
constexpr std::size_t getSize() const noexcept
Get the number of elements.
Definition: Span.h:555
constexpr T * getData() noexcept
Get a pointer to the elements.
Definition: Span.h:143
constexpr bool isEmpty() const noexcept
Check if the array is empty.
Definition: Span.h:173
constexpr Span(std::nullptr_t)
Null constructor.
Definition: Span.h:439
constexpr const T * getData() const noexcept
Get a pointer to the elements.
Definition: Span.h:153
constexpr StaticSpan(std::nullptr_t) noexcept
Null constructor.
Definition: Span.h:76
The namespace for gf classes.
Definition: Action.h:35
constexpr const T * getData() const noexcept
Get a pointer to the elements.
Definition: Span.h:546
constexpr StaticSpan(StaticSpan< U, N > other) noexcept
Constructor from another span.
Definition: Span.h:132
constexpr Span< T > lastExcept(std::size_t count) const noexcept
Take a span on the last objects.
Definition: Span.h:745
constexpr Span(U(&data)[N])
Constructor from a static array.
Definition: Span.h:502
Span(std::vector< U > &values)
Constructor from a std::vector
Definition: Span.h:464
constexpr const T & operator[](std::size_t index) const
Get an element at a given index.
Definition: Span.h:632
constexpr StaticSpan< T, E - B > slice() const noexcept
Take a constant sub-span.
Definition: Span.h:297
constexpr StaticSpan() noexcept
Default constructor.
Definition: Span.h:65
constexpr std::size_t getSize() const noexcept
Get the number of elements.
Definition: Span.h:163
constexpr Span< T > slice(std::size_t b, std::size_t e) const noexcept
Take a sub-span.
Definition: Span.h:644
constexpr const T & operator[](std::size_t index) const noexcept
Get an element at a given index.
Definition: Span.h:244
constexpr Span< T > lastExcept() const noexcept
Take a span on the last objects.
Definition: Span.h:757
constexpr Span< T > firstExcept(std::size_t count) const noexcept
Take a span on the first objects.
Definition: Span.h:720
constexpr Span(StaticSpan< U, N > other)
Constructor from another static span.
Definition: Span.h:526
constexpr void unused(Args &&...)
A simple way to avoid warnings about unused variables.
Definition: Unused.h:35
constexpr T * getData() noexcept
Get a pointer to the elements.
Definition: Span.h:537
constexpr Span(Span< U > other)
Constructor from another span.
Definition: Span.h:514
constexpr const T * end() const noexcept
Get an iterator past the last element.
Definition: Span.h:608
constexpr StaticSpan< T, C > first() const noexcept
Take a constant span on the first objects.
Definition: Span.h:683
constexpr StaticSpan(std::array< U, N > &array) noexcept
Constructor from a std::array
Definition: Span.h:120
constexpr StaticSpan< T, Size - C > lastExcept() const noexcept
Take a constant span on the last objects.
Definition: Span.h:395
constexpr Span(T *data, std::size_t size)
Constructor from a pointer and a size.
Definition: Span.h:452
constexpr Span< T > last(std::size_t count) const noexcept
Take a span on the last objects.
Definition: Span.h:333
constexpr Span()
Default constructor.
Definition: Span.h:427
constexpr StaticSpan< T, C > last() const noexcept
Take a constant span on the last objects.
Definition: Span.h:708