File indexing completed on 2025-09-15 08:51:38
0001 #ifndef BOOST_QVM_QUAT_TRAITS
0002 #define BOOST_QVM_QUAT_TRAITS
0003
0004
0005
0006
0007
0008 #include <boost/qvm/is_scalar.hpp>
0009 #include <boost/qvm/enable_if.hpp>
0010 #include <boost/qvm/config.hpp>
0011
0012 namespace boost { namespace qvm {
0013
0014 template <class Q>
0015 struct
0016 quat_traits
0017 {
0018 typedef void scalar_type;
0019 };
0020
0021 template <class T>
0022 struct
0023 is_quat
0024 {
0025 static bool const value = is_scalar<typename quat_traits<T>::scalar_type>::value;
0026 };
0027
0028 namespace
0029 qvm_detail
0030 {
0031 template <class T, T>
0032 struct
0033 qtr_dispatch_yes
0034 {
0035 char x, y;
0036 };
0037 }
0038
0039 template <class T>
0040 class
0041 quat_write_element_ref
0042 {
0043 template <class U>
0044 static qvm_detail::qtr_dispatch_yes<typename quat_traits<U>::scalar_type & (*)( U & ), &quat_traits<U>::template write_element<0> > check(int);
0045
0046 template <class>
0047 static char check(long);
0048
0049 public:
0050
0051 static bool const value = sizeof(check<T>(0)) > 1;
0052 };
0053
0054 template <int I, class Q>
0055 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0056 typename enable_if_c<
0057 quat_write_element_ref<Q>::value,
0058 void>::type
0059 write_quat_element( Q & q, typename quat_traits<Q>::scalar_type s )
0060 {
0061 quat_traits<Q>::template write_element<I>(q) = s;
0062 }
0063
0064 template <int I, class Q>
0065 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0066 typename enable_if_c<
0067 !quat_write_element_ref<Q>::value,
0068 void>::type
0069 write_quat_element( Q & q, typename quat_traits<Q>::scalar_type s )
0070 {
0071 quat_traits<Q>::template write_element<I>(q, s);
0072 }
0073
0074 template <class Q>
0075 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0076 typename enable_if_c<
0077 quat_write_element_ref<Q>::value,
0078 void>::type
0079 write_quat_element_idx( int i, Q & q, typename quat_traits<Q>::scalar_type s )
0080 {
0081 quat_traits<Q>::write_element_idx(i, q) = s;
0082 }
0083
0084 template <class Q>
0085 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0086 typename enable_if_c<
0087 !quat_write_element_ref<Q>::value,
0088 void>::type
0089 write_vec_element_idx( int i, Q & q, typename quat_traits<Q>::scalar_type s )
0090 {
0091 quat_traits<Q>::write_element_idx(i, q, s);
0092 }
0093
0094 } }
0095
0096 #endif