Add a macro to control if the result of binary operators should be casted.

It allows to suppress warnings when combining vectors of a type that
gets promoted to int after the binary operator is applied, for example.
This commit is contained in:
King_DuckZ 2016-11-02 01:14:23 +01:00
parent 6ab4d586eb
commit f51c739a48
2 changed files with 21 additions and 0 deletions

View file

@ -360,37 +360,57 @@ namespace vwr {
template <typename V1, typename V2>
inline Vec<typename std::common_type<V1, V2>::type> operator+ (const Vec<V1>& parLeft, const Vec<V2>& parRight) {
typedef typename VectorWrapperInfo<typename std::common_type<V1, V2>::type>::scalar_type scalar_type;
static_assert(static_cast<int>(VectorWrapperInfo<V1>::dimensions) == static_cast<int>(VectorWrapperInfo<V2>::dimensions), "Dimensions mismatch");
Vec<typename std::common_type<V1, V2>::type> retval;
for (int z = 0; z < VectorWrapperInfo<V1>::dimensions; ++z) {
#if defined(VWR_STATIC_CAST_RESULTS)
retval[z] = static_cast<scalar_type>(parLeft[z] + parRight[z]);
#else
retval[z] = parLeft[z] + parRight[z];
#endif
}
return retval;
}
template <typename V1, typename V2>
inline Vec<typename std::common_type<V1, V2>::type> operator- (const Vec<V1>& parLeft, const Vec<V2>& parRight) {
typedef typename VectorWrapperInfo<typename std::common_type<V1, V2>::type>::scalar_type scalar_type;
static_assert(static_cast<int>(VectorWrapperInfo<V1>::dimensions) == static_cast<int>(VectorWrapperInfo<V2>::dimensions), "Dimensions mismatch");
Vec<typename std::common_type<V1, V2>::type> retval;
for (int z = 0; z < VectorWrapperInfo<V1>::dimensions; ++z) {
#if defined(VWR_STATIC_CAST_RESULTS)
retval[z] = static_cast<scalar_type>(parLeft[z] - parRight[z]);
#else
retval[z] = parLeft[z] - parRight[z];
#endif
}
return retval;
}
template <typename V1, typename V2>
inline Vec<typename std::common_type<V1, V2>::type> operator* (const Vec<V1>& parLeft, const Vec<V2>& parRight) {
typedef typename VectorWrapperInfo<typename std::common_type<V1, V2>::type>::scalar_type scalar_type;
static_assert(static_cast<int>(VectorWrapperInfo<V1>::dimensions) == static_cast<int>(VectorWrapperInfo<V2>::dimensions), "Dimensions mismatch");
Vec<typename std::common_type<V1, V2>::type> retval;
for (int z = 0; z < VectorWrapperInfo<V1>::dimensions; ++z) {
#if defined(VWR_STATIC_CAST_RESULTS)
retval[z] = static_cast<scalar_type>(parLeft[z] * parRight[z]);
#else
retval[z] = parLeft[z] * parRight[z];
#endif
}
return retval;
}
template <typename V1, typename V2>
inline Vec<typename std::common_type<V1, V2>::type> operator/ (const Vec<V1>& parLeft, const Vec<V2>& parRight) {
typedef typename VectorWrapperInfo<typename std::common_type<V1, V2>::type>::scalar_type scalar_type;
static_assert(static_cast<int>(VectorWrapperInfo<V1>::dimensions) == static_cast<int>(VectorWrapperInfo<V2>::dimensions), "Dimensions mismatch");
Vec<typename std::common_type<V1, V2>::type> retval;
for (int z = 0; z < VectorWrapperInfo<V1>::dimensions; ++z) {
#if defined(VWR_STATIC_CAST_RESULTS)
retval[z] = static_cast<scalar_type>(parLeft[z] / parRight[z]);
#else
retval[z] = parLeft[z] / parRight[z];
#endif
}
return retval;
}