@@ -51,10 +51,25 @@ For more information, please refer to <https://unlicense.org> */
51
51
namespace fcarouge {
52
52
// ! @name Algebraic Types
53
53
// ! @{
54
- // ! @brief Matrix.
54
+ // ! @brief Naive matrix.
55
+ // !
56
+ // ! @details An array-of-arrays naive implementation matrix. The implementation
57
+ // ! is constexpr compatible.
58
+ // !
59
+ // ! @tparam Type The matrix element type.
60
+ // ! @tparam Row The number of rows of the matrix.
61
+ // ! @tparam Column The number of columns of the matrix.
55
62
template <typename Type = double , auto Row = 1 , auto Column = 1 > struct matrix {
56
63
inline constexpr matrix () = default;
57
64
65
+ inline constexpr matrix (const matrix &other) = default;
66
+
67
+ inline constexpr matrix &operator =(const matrix &other) = default ;
68
+
69
+ inline constexpr matrix (matrix &&other) = default;
70
+
71
+ inline constexpr matrix &operator =(matrix &&other) = default ;
72
+
58
73
inline constexpr explicit (false ) matrix(Type element)
59
74
requires(Row == 1 && Column == 1 )
60
75
{
@@ -68,30 +83,30 @@ template <typename Type = double, auto Row = 1, auto Column = 1> struct matrix {
68
83
}
69
84
70
85
inline constexpr explicit matrix (Type(column)[Row])
71
- requires(Row > 1 && Column == 1 )
86
+ requires(Row != 1 && Column == 1 )
72
87
{
73
88
for (decltype (Row) i{0 }; i < Row; ++i) {
74
89
data[i][0 ] = column[i];
75
90
}
76
91
}
77
92
78
93
inline constexpr explicit matrix (Type(row)[Column])
79
- requires(Row == 1 && Column > 1 )
94
+ requires(Row == 1 && Column != 1 )
80
95
{
81
96
for (decltype (Column) j{0 }; j < Column; ++j) {
82
97
data[0 ][j] = row[j];
83
98
}
84
99
}
85
100
86
101
inline constexpr matrix (const auto &...elements)
87
- requires(Row > 1 && Column == 1 && sizeof ...(elements) == Row)
102
+ requires(Row != 1 && Column == 1 && sizeof ...(elements) == Row)
88
103
{
89
104
decltype (Row) i{0 };
90
105
([&] { data[i++][0 ] = elements; }(), ...);
91
106
}
92
107
93
108
inline constexpr matrix (const auto &...elements)
94
- requires(Row == 1 && Column > 1 && sizeof ...(elements) == Column)
109
+ requires(Row == 1 && Column != 1 && sizeof ...(elements) == Column)
95
110
{
96
111
decltype (Column) j{0 };
97
112
([&] { data[0 ][j++] = elements; }(), ...);
@@ -108,42 +123,43 @@ template <typename Type = double, auto Row = 1, auto Column = 1> struct matrix {
108
123
}
109
124
}
110
125
111
- inline constexpr explicit (false ) operator Type() const
126
+ [[nodiscard]] inline constexpr explicit (false ) operator Type() const
112
127
requires(Row == 1 && Column == 1 )
113
128
{
114
129
return data[0 ][0 ];
115
130
}
116
131
117
- inline constexpr const Type &operator [](auto index) const
118
- requires (Row > 1 && Column == 1 )
132
+ [[nodiscard]] inline constexpr const Type &operator [](auto index) const
133
+ requires (Row != 1 && Column == 1 )
119
134
{
120
135
return data[index ][0 ];
121
136
}
122
137
123
- inline constexpr const Type &operator [](auto index) const
138
+ [[nodiscard]] inline constexpr const Type &operator [](auto index) const
124
139
requires (Row == 1 )
125
140
{
126
141
return data[0 ][index ];
127
142
}
128
143
129
- inline constexpr const Type &operator ()(auto index) const
130
- requires(Row > 1 && Column == 1 )
144
+ [[nodiscard]] inline constexpr const Type &operator ()(auto index) const
145
+ requires(Row != 1 && Column == 1 )
131
146
{
132
147
return data[index ][0 ];
133
148
}
134
149
135
- inline constexpr const Type &operator ()(auto index) const
150
+ [[nodiscard]] inline constexpr const Type &operator ()(auto index) const
136
151
requires(Row == 1 )
137
152
{
138
153
return data[0 ][index ];
139
154
}
140
155
141
- inline constexpr const Type &operator ()(auto row, auto column) const {
156
+ [[nodiscard]] inline constexpr const Type &operator ()(auto row,
157
+ auto column) const {
142
158
return data[row][column];
143
159
}
144
160
145
161
[[nodiscard]] inline constexpr bool operator ==(const matrix &other) const
146
- requires (Row > 1 || Column > 1 )
162
+ requires (Row != 1 || Column != 1 )
147
163
= default ;
148
164
149
165
[[no_unique_address]] Type data[Row][Column]{};
@@ -166,7 +182,14 @@ template <typename Type, auto Row, auto Column>
166
182
matrix (const Type (&)[Row][Column]) -> matrix<Type, Row, Column>;
167
183
168
184
template <typename Type, auto Row>
169
- matrix (const Type (&)[Row]) -> matrix<Type, Row, 1>; // column_vector
185
+ matrix (const Type (&)[Row]) -> matrix<Type, Row, 1>;
186
+
187
+ template <typename ... Types, auto ... Columns>
188
+ requires (std::conjunction_v<std::is_same<first_t <Types...>, Types>...> &&
189
+ ((Columns == first_v<Columns>)&&... && true))
190
+ matrix(const Types (&...rows)[Columns])
191
+ -> matrix<std::remove_cvref_t<first_t<Types...>>, sizeof...(Columns),
192
+ (Columns, ...)>;
170
193
// ! @}
171
194
172
195
// ! @name Algebraic Named Values
0 commit comments