12#ifndef RTCTK_COMPONENTFRAMEWORK_MATRIXSPAN_HPP
13#define RTCTK_COMPONENTFRAMEWORK_MATRIXSPAN_HPP
37 using typename gsl::span<T>::element_type;
38 using typename gsl::span<T>::value_type;
39 using typename gsl::span<T>::size_type;
40 using typename gsl::span<T>::pointer;
42 using typename gsl::span<T>::reference;
44 using typename gsl::span<T>::iterator;
45 using typename gsl::span<T>::reverse_iterator;
47 constexpr MatrixSpan() noexcept : gsl::span<T>(), m_nrows(0), m_ncols(0) {
51 : gsl::span<T>(other), m_nrows(other.m_nrows), m_ncols(other.m_ncols) {
55 gsl::span<T>::operator=(other);
56 m_nrows = other.m_nrows;
57 m_ncols = other.m_ncols;
62 : gsl::span<T>(std::forward<MatrixSpan>(other))
63 , m_nrows(std::move(other.m_nrows))
64 , m_ncols(std::move(other.m_ncols)) {
68 gsl::span<T>::operator=(std::forward<MatrixSpan>(other));
69 m_nrows = std::move(other.m_nrows);
70 m_ncols = std::move(other.m_ncols);
74 constexpr explicit MatrixSpan(size_type n, size_type m,
const gsl::span<T>& data)
75 : gsl::span<T>(data), m_nrows(n), m_ncols(m) {
76 assert(n * m == data.size());
80 constexpr explicit MatrixSpan(size_type n, size_type m, I first, size_type count)
81 : gsl::span<T>(first, count), m_nrows(n), m_ncols(m) {
82 assert(n * m == count);
86 constexpr explicit MatrixSpan(size_type n, size_type m, I first, I last)
87 : gsl::span<T>(first, last), m_nrows(n), m_ncols(m) {
88 assert(n * m ==
static_cast<size_type
>(std::distance(first, last)));
93 template <std::
size_t N>
94 constexpr explicit MatrixSpan(size_type n, size_type m, element_type (&array)[N]) noexcept
95 : gsl::span<T>(array), m_nrows(n), m_ncols(m) {
100 template <std::
size_t N>
101 constexpr explicit MatrixSpan(size_type n, size_type m, std::array<T, N>& array) noexcept
102 : gsl::span<T>(array), m_nrows(n), m_ncols(m) {
106 template <std::
size_t N>
107 constexpr explicit MatrixSpan(size_type n, size_type m,
const std::array<T, N>& array) noexcept
108 : gsl::span<T>(array), m_nrows(n), m_ncols(m) {
112 template <
typename R>
113 constexpr explicit MatrixSpan(size_type n, size_type m, R&& range) noexcept
114 : gsl::span<T>(std::forward<R>(range)), m_nrows(n), m_ncols(m) {
115 assert(n * m == range.size());
118 template <
typename A>
120 : gsl::span<T>(buffer.data(), buffer.size())
121 , m_nrows(buffer.GetNrows())
122 , m_ncols(buffer.GetNcols()) {
125 template <
typename A>
126 requires std::is_const_v<T> or std::is_volatile_v<T>
128 : gsl::span<T>(buffer.data(), buffer.size())
129 , m_nrows(buffer.GetNrows())
130 , m_ncols(buffer.GetNcols()) {
133 template <
typename U>
134 requires std::is_same_v<std::remove_cv_t<T>, std::remove_cv_t<U>>
136 return std::equal(this->begin(), this->end(), rhs.begin(), rhs.end());
141 assert(0 <= n and n < m_nrows);
143 assert(0 <= m and m < m_ncols);
144 return gsl::span<T>::operator[](n * m_ncols + m);
149 assert(0 <= n and n < m_nrows);
151 assert(0 <= m and m < m_ncols);
152 return gsl::span<T>::operator[](n * m_ncols + m);
164 return row * m_ncols + col;
A buffer class representing 2D matrix data.
Definition matrixBuffer.hpp:27
bool operator==(const MatrixSpan< U > &rhs) const
Definition matrixSpan.hpp:135
const T & const_reference
Definition matrixSpan.hpp:43
constexpr MatrixSpan(MatrixBuffer< std::remove_cv_t< T >, A > &buffer) noexcept
Definition matrixSpan.hpp:127
constexpr MatrixSpan(size_type n, size_type m, R &&range) noexcept
Definition matrixSpan.hpp:113
constexpr MatrixSpan(size_type n, size_type m, I first, I last)
Definition matrixSpan.hpp:86
size_type GetNrows() const
Definition matrixSpan.hpp:155
constexpr MatrixSpan(size_type n, size_type m, const gsl::span< T > &data)
Definition matrixSpan.hpp:74
constexpr MatrixSpan(const MatrixSpan &other)
Definition matrixSpan.hpp:50
constexpr MatrixSpan(MatrixBuffer< T, A > &buffer) noexcept
Definition matrixSpan.hpp:119
constexpr MatrixSpan & operator=(const MatrixSpan &other)
Definition matrixSpan.hpp:54
constexpr MatrixSpan(size_type n, size_type m, I first, size_type count)
Definition matrixSpan.hpp:80
constexpr reference operator()(size_type n, size_type m)
Definition matrixSpan.hpp:139
size_type GetNcols() const
Definition matrixSpan.hpp:159
constexpr MatrixSpan(size_type n, size_type m, element_type(&array)[N]) noexcept
Definition matrixSpan.hpp:94
constexpr MatrixSpan() noexcept
Definition matrixSpan.hpp:47
constexpr MatrixSpan(size_type n, size_type m, std::array< T, N > &array) noexcept
Definition matrixSpan.hpp:101
constexpr const_reference operator()(size_type n, size_type m) const
Definition matrixSpan.hpp:147
size_t GetElementIndex(size_t row, size_t col)
Definition matrixSpan.hpp:163
constexpr MatrixSpan(MatrixSpan &&other) noexcept
Definition matrixSpan.hpp:61
constexpr MatrixSpan & operator=(MatrixSpan &&other) noexcept
Definition matrixSpan.hpp:67
const T * const_pointer
Definition matrixSpan.hpp:41
constexpr MatrixSpan(size_type n, size_type m, const std::array< T, N > &array) noexcept
Definition matrixSpan.hpp:107
Declaration of the MatrixBuffer template class used in APIs.
Definition commandReplier.cpp:21