1#ifndef BOOST_QVM_TRAITS_HPP_INCLUDED
2#define BOOST_QVM_TRAITS_HPP_INCLUDED
3
4// Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc.
5
6// Distributed under the Boost Software License, Version 1.0. (See accompanying
7// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8
9#include <boost/qvm/is_scalar.hpp>
10#include <boost/qvm/enable_if.hpp>
11#include <boost/qvm/config.hpp>
12
13namespace boost { namespace qvm {
14
15template <class M>
16struct
17mat_traits
18 {
19 static int const rows=0;
20 static int const cols=0;
21 typedef void scalar_type;
22 };
23
24template <class T>
25struct
26is_mat
27 {
28 static bool const value = is_scalar<typename mat_traits<T>::scalar_type>::value && mat_traits<T>::rows>0 && mat_traits<T>::cols>0;
29 };
30
31namespace
32qvm_detail
33 {
34 template <class T, T>
35 struct
36 mtr_dispatch_yes
37 {
38 char x, y;
39 };
40 }
41
42template <class T>
43class
44mat_write_element_ref
45 {
46 template <class U>
47 static qvm_detail::mtr_dispatch_yes<typename mat_traits<U>::scalar_type & (*)( U & ), &mat_traits<U>::template write_element<0,0> > check(int);
48
49 template <class>
50 static char check(long);
51
52 public:
53
54 static bool const value = sizeof(check<T>(0)) > 1;
55 };
56
57template <int R, int C, class M>
58BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
59typename enable_if_c<
60 mat_write_element_ref<M>::value,
61 void>::type
62write_mat_element( M & m, typename mat_traits<M>::scalar_type s )
63 {
64 mat_traits<M>::template write_element<R,C>(m) = s;
65 }
66
67template <int R, int C, class M>
68BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
69typename enable_if_c<
70 !mat_write_element_ref<M>::value,
71 void>::type
72write_mat_element( M & m, typename mat_traits<M>::scalar_type s )
73 {
74 mat_traits<M>::template write_element<R,C>(m, s);
75 }
76
77template <class M>
78BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
79typename enable_if_c<
80 mat_write_element_ref<M>::value,
81 void>::type
82write_mat_element_idx( int r, int c, M & m, typename mat_traits<M>::scalar_type s )
83 {
84 mat_traits<M>::write_element_idx(r, c, m) = s;
85 }
86
87template <class M>
88BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
89typename enable_if_c<
90 !mat_write_element_ref<M>::value,
91 void>::type
92write_mat_element_idx( int r, int c, M & m, typename mat_traits<M>::scalar_type s )
93 {
94 mat_traits<M>::write_element_idx(r, c, m, s);
95 }
96
97} }
98
99#endif
100

source code of boost/libs/qvm/include/boost/qvm/mat_traits.hpp