C++11: Got rid of narrowing conversion warnings in legacy code.
Added explicit static_cast along with static SFINAE checks to VectorT constructor.
This commit is contained in:
@@ -92,6 +92,23 @@ namespace OpenMesh {
|
|||||||
//== CLASS DEFINITION =========================================================
|
//== CLASS DEFINITION =========================================================
|
||||||
|
|
||||||
|
|
||||||
|
#if CPP11_ENABLED
|
||||||
|
/*
|
||||||
|
* Helpers for VectorT
|
||||||
|
*/
|
||||||
|
namespace {
|
||||||
|
template<typename... Ts>
|
||||||
|
struct are_convertible_to;
|
||||||
|
|
||||||
|
template<typename To, typename From, typename... Froms>
|
||||||
|
struct are_convertible_to<To, From, Froms...> {
|
||||||
|
static constexpr bool value = std::is_convertible<From, To>::value && are_convertible_to<To, Froms...>::value;
|
||||||
|
};
|
||||||
|
template<typename To, typename From>
|
||||||
|
struct are_convertible_to<To, From> : public std::is_convertible<From, To> {};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/** The N values of the template Scalar type are the only data members
|
/** The N values of the template Scalar type are the only data members
|
||||||
of the class VectorT<Scalar,N>. This guarantees 100% compatibility
|
of the class VectorT<Scalar,N>. This guarantees 100% compatibility
|
||||||
|
|||||||
@@ -102,8 +102,10 @@ public:
|
|||||||
vectorize(v);
|
vectorize(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... T, typename = typename std::enable_if<sizeof...(T) == DIM>::type>
|
template<typename... T,
|
||||||
constexpr VectorT(T... vs) : Base {vs...}
|
typename = typename std::enable_if<sizeof...(T) == DIM>::type,
|
||||||
|
typename = typename std::enable_if<are_convertible_to<float, T...>::value>::type>
|
||||||
|
constexpr VectorT(T... vs) : Base { static_cast<Scalar>(vs)...}
|
||||||
{ }
|
{ }
|
||||||
#else
|
#else
|
||||||
/// special constructor for 1D vectors
|
/// special constructor for 1D vectors
|
||||||
|
|||||||
Reference in New Issue
Block a user