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 =========================================================
|
||||
|
||||
|
||||
#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
|
||||
of the class VectorT<Scalar,N>. This guarantees 100% compatibility
|
||||
|
||||
@@ -102,8 +102,10 @@ public:
|
||||
vectorize(v);
|
||||
}
|
||||
|
||||
template<typename... T, typename = typename std::enable_if<sizeof...(T) == DIM>::type>
|
||||
constexpr VectorT(T... vs) : Base {vs...}
|
||||
template<typename... T,
|
||||
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
|
||||
/// special constructor for 1D vectors
|
||||
|
||||
Reference in New Issue
Block a user