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