@@ -70,46 +70,31 @@ template <typename Type = double, auto Row = 1, auto Column = 1> struct matrix {
70
70
71
71
inline constexpr matrix &operator =(matrix &&other) = default ;
72
72
73
- inline constexpr explicit (false ) matrix(Type element)
74
- requires(Row == 1 && Column == 1 )
75
- {
76
- data[0 ][0 ] = element;
77
- }
78
-
79
- inline constexpr explicit matrix (Type(element)[1])
80
- requires(Row == 1 && Column == 1 )
81
- {
82
- data[0 ][0 ] = element[0 ];
83
- }
73
+ inline constexpr matrix (const std::same_as<Type> auto &...elements)
74
+ requires(Row == 1 && sizeof ...(elements) == Column)
75
+ : data{{elements...}} {}
84
76
85
- inline constexpr explicit matrix (Type(column)[Row] )
86
- requires(Row != 1 && Column == 1 )
77
+ inline constexpr matrix (const std::same_as< Type> auto &...elements )
78
+ requires(Row != 1 && Column == 1 && sizeof ...(elements) == Row )
87
79
{
88
- for (decltype (Row) i{0 }; i < Row; ++i) {
89
- data[i][0 ] = column[i];
90
- }
80
+ decltype (Row) i{0 };
81
+ ([&] { data[i++][0 ] = elements; }(), ...);
91
82
}
92
83
93
- inline constexpr explicit matrix (Type(row )[Column])
94
- requires(Row == 1 && Column != 1 )
84
+ inline constexpr explicit matrix (Type (&elements )[Column])
85
+ requires(Row == 1 )
95
86
{
96
87
for (decltype (Column) j{0 }; j < Column; ++j) {
97
- data[0 ][j] = row [j];
88
+ data[0 ][j] = elements [j];
98
89
}
99
90
}
100
91
101
- inline constexpr matrix (const auto &...elements)
102
- requires(Row != 1 && Column == 1 && sizeof ...(elements) == Row)
103
- {
104
- decltype (Row) i{0 };
105
- ([&] { data[i++][0 ] = elements; }(), ...);
106
- }
107
-
108
- inline constexpr matrix (const auto &...elements)
109
- requires(Row == 1 && Column != 1 && sizeof ...(elements) == Column)
92
+ inline constexpr explicit matrix (Type (&elements)[Row])
93
+ requires(Row != 1 && Column == 1 )
110
94
{
111
- decltype (Column) j{0 };
112
- ([&] { data[0 ][j++] = elements; }(), ...);
95
+ for (decltype (Row) i{0 }; i < Row; ++i) {
96
+ data[i][0 ] = elements[i];
97
+ }
113
98
}
114
99
115
100
inline constexpr explicit matrix (
@@ -158,10 +143,6 @@ template <typename Type = double, auto Row = 1, auto Column = 1> struct matrix {
158
143
return data[row][column];
159
144
}
160
145
161
- [[nodiscard]] inline constexpr bool operator ==(const matrix &other) const
162
- requires (Row != 1 || Column != 1 )
163
- = default ;
164
-
165
146
[[no_unique_address]] Type data[Row][Column]{};
166
147
};
167
148
@@ -219,6 +200,20 @@ template <typename Type, auto Row, auto Column>
219
200
inline constexpr matrix<Type, Row, Column> zero_v<matrix<Type, Row, Column>>{};
220
201
// ! @}
221
202
203
+ template <typename Type, auto Row, auto Column>
204
+ [[nodiscard]] inline constexpr bool
205
+ operator ==(const matrix<Type, Row, Column> &lhs,
206
+ const matrix<Type, Row, Column> &rhs) {
207
+ for (decltype (Row) i{0 }; i < Row; ++i) {
208
+ for (decltype (Column) j{0 }; j < Column; ++j) {
209
+ if (lhs.data [i][j] != rhs.data [i][j]) {
210
+ return false ;
211
+ }
212
+ }
213
+ }
214
+ return true ;
215
+ }
216
+
222
217
template <typename Type, auto Row, auto Column, auto Size >
223
218
[[nodiscard]] inline constexpr auto
224
219
operator *(const matrix<Type, Row, Size > &lhs,
0 commit comments