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