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