File indexing completed on 2025-09-17 08:49:50
0001 #ifndef BOOST_QVM_MAT_TRAITS_ARRAY_HPP_INCLUDED
0002 #define BOOST_QVM_MAT_TRAITS_ARRAY_HPP_INCLUDED
0003
0004
0005
0006
0007
0008 #include <boost/qvm/config.hpp>
0009 #include <boost/qvm/deduce_mat.hpp>
0010 #include <boost/qvm/assert.hpp>
0011
0012 #if __cplusplus > 199711L
0013
0014 #include <array>
0015
0016 namespace boost { namespace qvm {
0017
0018 template <class T,std::size_t R,std::size_t Q,std::size_t C>
0019 struct
0020 mat_traits<std::array<std::array<std::array<T,R>,Q>,C> >
0021 {
0022 static int const rows=0;
0023 static int const cols=0;
0024 typedef void scalar_type;
0025 };
0026
0027 template <class T,std::size_t Rows,std::size_t Cols>
0028 struct
0029 mat_traits<std::array<std::array<T,Rows>,Cols> >
0030 {
0031 typedef std::array<std::array<T,Rows>,Cols> this_matrix;
0032 typedef T scalar_type;
0033 static int const rows=Rows;
0034 static int const cols=Cols;
0035
0036 template <int Row,int Col>
0037 static
0038 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0039 scalar_type
0040 read_element( this_matrix const & x )
0041 {
0042 BOOST_QVM_STATIC_ASSERT(Row>=0);
0043 BOOST_QVM_STATIC_ASSERT(Row<rows);
0044 BOOST_QVM_STATIC_ASSERT(Col>=0);
0045 BOOST_QVM_STATIC_ASSERT(Col<cols);
0046 return x[Row][Col];
0047 }
0048
0049 template <int Row,int Col>
0050 static
0051 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0052 scalar_type &
0053 write_element( this_matrix & x )
0054 {
0055 BOOST_QVM_STATIC_ASSERT(Row>=0);
0056 BOOST_QVM_STATIC_ASSERT(Row<rows);
0057 BOOST_QVM_STATIC_ASSERT(Col>=0);
0058 BOOST_QVM_STATIC_ASSERT(Col<cols);
0059 return x[Row][Col];
0060 }
0061
0062 static
0063 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0064 scalar_type
0065 read_element_idx( int row, int col, this_matrix const & x )
0066 {
0067 BOOST_QVM_ASSERT(row>=0);
0068 BOOST_QVM_ASSERT(row<rows);
0069 BOOST_QVM_ASSERT(col>=0);
0070 BOOST_QVM_ASSERT(col<cols);
0071 return x[row][col];
0072 }
0073
0074 static
0075 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0076 scalar_type &
0077 write_element_idx( int row, int col, this_matrix & x )
0078 {
0079 BOOST_QVM_ASSERT(row>=0);
0080 BOOST_QVM_ASSERT(row<rows);
0081 BOOST_QVM_ASSERT(col>=0);
0082 BOOST_QVM_ASSERT(col<cols);
0083 return x[row][col];
0084 }
0085 };
0086
0087 template <class T,std::size_t Rows,std::size_t Cols>
0088 struct
0089 mat_traits<std::array<std::array<T,Rows>,Cols> const>
0090 {
0091 typedef std::array<std::array<T,Rows>,Cols> const this_matrix;
0092 typedef T scalar_type;
0093 static int const rows=Rows;
0094 static int const cols=Cols;
0095
0096 template <int Row,int Col>
0097 static
0098 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0099 scalar_type
0100 read_element( this_matrix & x )
0101 {
0102 BOOST_QVM_STATIC_ASSERT(Row>=0);
0103 BOOST_QVM_STATIC_ASSERT(Row<rows);
0104 BOOST_QVM_STATIC_ASSERT(Col>=0);
0105 BOOST_QVM_STATIC_ASSERT(Col<cols);
0106 return x[Row][Col];
0107 }
0108
0109 static
0110 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0111 scalar_type
0112 read_element_idx( int row, int col, this_matrix & x )
0113 {
0114 BOOST_QVM_ASSERT(row>=0);
0115 BOOST_QVM_ASSERT(row<rows);
0116 BOOST_QVM_ASSERT(col>=0);
0117 BOOST_QVM_ASSERT(col<cols);
0118 return x[row][col];
0119 }
0120 };
0121
0122 template <class T,std::size_t Rows,std::size_t Cols,int R,int C>
0123 struct
0124 deduce_mat<std::array<std::array<T,Rows>,Cols>,R,C>
0125 {
0126 typedef mat<T,R,C> type;
0127 };
0128
0129 template <class T,std::size_t Rows,std::size_t Cols,int R,int C>
0130 struct
0131 deduce_mat<std::array<std::array<T,Rows>,Cols> const,R,C>
0132 {
0133 typedef mat<T,R,C> type;
0134 };
0135
0136 template <class T1,class T2,std::size_t Rows,std::size_t Cols,int R,int C>
0137 struct
0138 deduce_mat2<std::array<std::array<T1,Rows>,Cols>,std::array<std::array<T2,Rows>,Cols>,R,C>
0139 {
0140 typedef mat<typename deduce_scalar<T1,T2>::type,R,C> type;
0141 };
0142
0143 template <class T1,class T2,std::size_t Rows,std::size_t Cols,int R,int C>
0144 struct
0145 deduce_mat2<std::array<std::array<T1,Rows>,Cols> const,std::array<std::array<T2,Rows>,Cols>,R,C>
0146 {
0147 typedef mat<typename deduce_scalar<T1,T2>::type,R,C> type;
0148 };
0149
0150 template <class T1,class T2,std::size_t Rows,std::size_t Cols,int R,int C>
0151 struct
0152 deduce_mat2<std::array<std::array<T1,Rows>,Cols>,std::array<std::array<T2,Rows> const,Cols>,R,C>
0153 {
0154 typedef mat<typename deduce_scalar<T1,T2>::type,R,C> type;
0155 };
0156
0157 template <class T1,class T2,std::size_t Rows,std::size_t Cols,int R,int C>
0158 struct
0159 deduce_mat2<std::array<std::array<T1,Rows>,Cols> const,std::array<std::array<T2,Rows>,Cols> const,R,C>
0160 {
0161 typedef mat<typename deduce_scalar<T1,T2>::type,R,C> type;
0162 };
0163
0164 } }
0165
0166 #endif
0167
0168 namespace boost { namespace qvm {
0169
0170 template <class T,int R,int Q,int C>
0171 struct
0172 mat_traits<T[R][Q][C]>
0173 {
0174 static int const rows=0;
0175 static int const cols=0;
0176 typedef void scalar_type;
0177 };
0178
0179 template <class T,int Rows,int Cols>
0180 struct
0181 mat_traits<T[Rows][Cols]>
0182 {
0183 typedef T this_matrix[Rows][Cols];
0184 typedef T scalar_type;
0185 static int const rows=Rows;
0186 static int const cols=Cols;
0187
0188 template <int Row,int Col>
0189 static
0190 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0191 scalar_type
0192 read_element( this_matrix const & x )
0193 {
0194 BOOST_QVM_STATIC_ASSERT(Row>=0);
0195 BOOST_QVM_STATIC_ASSERT(Row<rows);
0196 BOOST_QVM_STATIC_ASSERT(Col>=0);
0197 BOOST_QVM_STATIC_ASSERT(Col<cols);
0198 return x[Row][Col];
0199 }
0200
0201 template <int Row,int Col>
0202 static
0203 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0204 scalar_type &
0205 write_element( this_matrix & x )
0206 {
0207 BOOST_QVM_STATIC_ASSERT(Row>=0);
0208 BOOST_QVM_STATIC_ASSERT(Row<rows);
0209 BOOST_QVM_STATIC_ASSERT(Col>=0);
0210 BOOST_QVM_STATIC_ASSERT(Col<cols);
0211 return x[Row][Col];
0212 }
0213
0214 static
0215 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0216 scalar_type
0217 read_element_idx( int row, int col, this_matrix const & x )
0218 {
0219 BOOST_QVM_ASSERT(row>=0);
0220 BOOST_QVM_ASSERT(row<Rows);
0221 BOOST_QVM_ASSERT(col>=0);
0222 BOOST_QVM_ASSERT(col<Cols);
0223 return x[row][col];
0224 }
0225
0226 static
0227 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0228 scalar_type &
0229 write_element_idx( int row, int col, this_matrix & x )
0230 {
0231 BOOST_QVM_ASSERT(row>=0);
0232 BOOST_QVM_ASSERT(row<Rows);
0233 BOOST_QVM_ASSERT(col>=0);
0234 BOOST_QVM_ASSERT(col<Cols);
0235 return x[row][col];
0236 }
0237 };
0238
0239 template <class T,int Rows,int Cols,int R,int C>
0240 struct
0241 deduce_mat<T[Rows][Cols],R,C>
0242 {
0243 typedef mat<T,R,C> type;
0244 };
0245
0246 template <class T,int Rows,int Cols,int R,int C>
0247 struct
0248 deduce_mat<T const[Rows][Cols],R,C>
0249 {
0250 typedef mat<T,R,C> type;
0251 };
0252
0253 template <class T1,class T2,int Rows,int Cols,int R,int C>
0254 struct
0255 deduce_mat2<T1[Rows][Cols],T2[Rows][Cols],R,C>
0256 {
0257 typedef mat<typename deduce_scalar<T1,T2>::type,R,C> type;
0258 };
0259
0260 template <int Rows,int Cols,class T>
0261 T (&ptr_mref( T * ptr ))[Rows][Cols]
0262 {
0263 return *reinterpret_cast<T (*)[Rows][Cols]>(ptr);
0264 }
0265
0266 } }
0267
0268 #endif