coord/ops: use common_type for results
This commit is contained in:
parent
d73e86b374
commit
5ed95ec952
@ -102,10 +102,11 @@ namespace util {
|
|||||||
typename U, \
|
typename U, \
|
||||||
template <size_t,typename> class K \
|
template <size_t,typename> class K \
|
||||||
> \
|
> \
|
||||||
typename std::enable_if<std::is_fundamental<U>::value, K<S,T>>::type \
|
K<S,typename std::common_type<T,U>::type> \
|
||||||
operator OP (U u, K<S,T> k) \
|
operator OP (U u, K<S,T> k) \
|
||||||
{ \
|
{ \
|
||||||
K<S,T> out; \
|
using out_t = typename std::common_type<T,U>::type; \
|
||||||
|
K<S,out_t> out; \
|
||||||
for (size_t i = 0; i < S; ++i) \
|
for (size_t i = 0; i < S; ++i) \
|
||||||
out[i] = u OP k[i]; \
|
out[i] = u OP k[i]; \
|
||||||
return out; \
|
return out; \
|
||||||
@ -117,10 +118,11 @@ namespace util {
|
|||||||
typename U, \
|
typename U, \
|
||||||
template <size_t,typename> class K \
|
template <size_t,typename> class K \
|
||||||
> \
|
> \
|
||||||
typename std::enable_if<std::is_fundamental<U>::value, K<S,T>>::type \
|
K<S,typename std::common_type<T,U>::type> \
|
||||||
operator OP (K<S,T> k, U u) \
|
operator OP (K<S,T> k, U u) \
|
||||||
{ \
|
{ \
|
||||||
K<S,T> out; \
|
using out_t = typename std::common_type<T,U>::type; \
|
||||||
|
K<S,out_t> out; \
|
||||||
for (size_t i = 0; i < S; ++i) \
|
for (size_t i = 0; i < S; ++i) \
|
||||||
out[i] = k[i] OP u; \
|
out[i] = k[i] OP u; \
|
||||||
return out; \
|
return out; \
|
||||||
@ -136,17 +138,27 @@ namespace util {
|
|||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
// scalar assignment operators.
|
||||||
|
//
|
||||||
|
// we must check the operands/results do not need casting to store in the
|
||||||
|
// destination type to avoid silent errors accumulating.
|
||||||
#define SCALAR_OP(OP) \
|
#define SCALAR_OP(OP) \
|
||||||
template < \
|
template < \
|
||||||
size_t S, \
|
size_t S, \
|
||||||
typename T, \
|
typename T, \
|
||||||
|
typename U, \
|
||||||
template <size_t,typename> class K \
|
template <size_t,typename> class K \
|
||||||
> \
|
> \
|
||||||
K<S,T>& \
|
typename std::enable_if< \
|
||||||
operator OP (K<S,T> &k, T t) \
|
std::is_same< \
|
||||||
|
T, \
|
||||||
|
typename std::common_type<T,U>::type>::value, \
|
||||||
|
K<S,T> \
|
||||||
|
>::type& \
|
||||||
|
operator OP (K<S,T> &k, U u) \
|
||||||
{ \
|
{ \
|
||||||
for (size_t i = 0; i < S; ++i) \
|
for (size_t i = 0; i < S; ++i) \
|
||||||
k[i] OP t; \
|
k[i] OP u; \
|
||||||
return k; \
|
return k; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user