File indexing completed on 2025-09-18 09:04:04
0001 #ifndef BOOST_QVM_TRAITS_HPP_INCLUDED
0002 #define BOOST_QVM_TRAITS_HPP_INCLUDED
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 M>
0015 struct
0016 mat_traits
0017 {
0018 static int const rows=0;
0019 static int const cols=0;
0020 typedef void scalar_type;
0021 };
0022
0023 template <class T>
0024 struct
0025 is_mat
0026 {
0027 static bool const value = is_scalar<typename mat_traits<T>::scalar_type>::value && mat_traits<T>::rows>0 && mat_traits<T>::cols>0;
0028 };
0029
0030 namespace
0031 qvm_detail
0032 {
0033 template <class T, T>
0034 struct
0035 mtr_dispatch_yes
0036 {
0037 char x, y;
0038 };
0039 }
0040
0041 template <class T>
0042 class
0043 mat_write_element_ref
0044 {
0045 template <class U>
0046 static qvm_detail::mtr_dispatch_yes<typename mat_traits<U>::scalar_type & (*)( U & ), &mat_traits<U>::template write_element<0,0> > check(int);
0047
0048 template <class>
0049 static char check(long);
0050
0051 public:
0052
0053 static bool const value = sizeof(check<T>(0)) > 1;
0054 };
0055
0056 template <int R, int C, class M>
0057 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0058 typename enable_if_c<
0059 mat_write_element_ref<M>::value,
0060 void>::type
0061 write_mat_element( M & m, typename mat_traits<M>::scalar_type s )
0062 {
0063 mat_traits<M>::template write_element<R,C>(m) = s;
0064 }
0065
0066 template <int R, int C, class M>
0067 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0068 typename enable_if_c<
0069 !mat_write_element_ref<M>::value,
0070 void>::type
0071 write_mat_element( M & m, typename mat_traits<M>::scalar_type s )
0072 {
0073 mat_traits<M>::template write_element<R,C>(m, s);
0074 }
0075
0076 template <class M>
0077 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0078 typename enable_if_c<
0079 mat_write_element_ref<M>::value,
0080 void>::type
0081 write_mat_element_idx( int r, int c, M & m, typename mat_traits<M>::scalar_type s )
0082 {
0083 mat_traits<M>::write_element_idx(r, c, m) = s;
0084 }
0085
0086 template <class M>
0087 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0088 typename enable_if_c<
0089 !mat_write_element_ref<M>::value,
0090 void>::type
0091 write_mat_element_idx( int r, int c, M & m, typename mat_traits<M>::scalar_type s )
0092 {
0093 mat_traits<M>::write_element_idx(r, c, m, s);
0094 }
0095
0096 } }
0097
0098 #endif