12#include <dr/detail/index.hpp>
20template <
typename T,
typename I = std::
size_t>
class matrix_entry {
26 : index_(
index), value_(value) {}
28 : index_(
index), value_(std::move(value)) {}
31 requires(std::is_constructible_v<T, U>)
33 : index_(
index), value_(std::forward<U>(value)) {}
35 template <
typename Entry>
38 : index_(std::get<0>(entry)), value_(std::get<1>(entry)) {}
40 template <std::
size_t Index>
auto get()
const noexcept {
41 if constexpr (Index == 0) {
44 if constexpr (Index == 1) {
49 operator std::pair<std::pair<I, I>, T>()
const noexcept {
50 return {{index_[0], index_[1]}, value_};
55 map_type value()
const noexcept {
return value_; }
57 template <std::
integral U>
58 requires(!std::is_same_v<I, U> &&
59 std::numeric_limits<U>::max() >= std::numeric_limits<I>::max())
64 template <std::
integral U>
65 requires(!std::is_const_v<T> && !std::is_same_v<I, U> &&
66 std::numeric_limits<U>::max() >= std::numeric_limits<I>::max())
67 operator matrix_entry<std::add_const_t<T>, U>()
const noexcept {
71 inline bool operator<(
const matrix_entry &other)
const noexcept {
72 if (index_.first != other.index_.first) {
73 return index_.first < other.index_.first;
75 return index_.second < other.index_.second;
95template <
typename T,
typename I>
96 requires(!std::is_const_v<T>)
103template <std::
size_t Index,
typename T,
typename I>
104struct tuple_element<Index, dr::matrix_entry<T, I>>
105 : tuple_element<Index, std::tuple<dr::index<I>, T>> {};
107template <
typename T,
typename I>
108struct tuple_size<dr::matrix_entry<T, I>> : integral_constant<size_t, 2> {};
114template <
typename T,
typename I = std::
size_t,
typename TRef = T &>
117 using scalar_type = T;
118 using index_type = I;
123 using scalar_reference = TRef;
128 : index_(
index), value_(value) {}
132 operator std::pair<std::pair<I, I>, T>()
const noexcept {
133 return {{index_[0], index_[1]}, value_};
136 template <std::
size_t Index>
137 decltype(
auto) get()
const noexcept
140 if constexpr (Index == 0) {
143 if constexpr (Index == 1) {
150 scalar_reference value()
const noexcept {
return value_; }
152 template <std::
integral U>
153 requires(!std::is_same_v<I, U> &&
154 std::numeric_limits<U>::max() >= std::numeric_limits<I>::max())
159 template <std::
integral U>
160 requires(!std::is_const_v<T> && !std::is_same_v<I, U> &&
161 std::numeric_limits<U>::max() >= std::numeric_limits<I>::max())
162 operator matrix_ref<std::add_const_t<T>, U, TRef>()
const noexcept {
167 if (
index()[0] < other.index()[0]) {
169 }
else if (
index()[0] == other.index()[0] &&
170 index()[1] < other.index()[1]) {
186 scalar_reference value_;
193template <
typename T,
typename I,
typename TRef>
194 requires(!std::is_const_v<T>)
201template <std::
size_t Index,
typename T,
typename I,
typename TRef>
202struct tuple_element<Index, dr::matrix_ref<T, I, TRef>>
203 : tuple_element<Index, std::tuple<dr::index<I>, TRef>> {};
205template <
typename T,
typename I,
typename TRef>
206struct tuple_size<dr::matrix_ref<T, I, TRef>>
207 : integral_constant<std::size_t, 2> {};
209template <std::
size_t Index,
typename T,
typename I,
typename TRef>
213 if constexpr (Index == 0) {
216 if constexpr (Index == 1) {
221template <std::
size_t Index,
typename T,
typename I,
typename TRef>
225 if constexpr (Index == 0) {
226 return entry.index();
228 if constexpr (Index == 1) {
229 return entry.value();
Definition: matrix_entry.hpp:20
Definition: matrix_entry.hpp:115
Definition: matrix_entry.hpp:16