make Vector11T converting ctor only accept at least 2 arguments

(hence making all single-argument ctors explicit)
This commit is contained in:
Janis Born
2017-02-10 15:55:29 +01:00
parent 6877007354
commit 0f42d48cfb

View File

@@ -112,14 +112,16 @@ class VectorT {
//-------------------------------------------------------------- constructors //-------------------------------------------------------------- constructors
template<typename ... T, // Converting constructor: Constructs the vector from DIM values (of
typename = typename std::enable_if<sizeof...(T) == DIM>::type, // potentially heterogenous types) which are all convertible to Scalar.
template<typename T, typename ... Ts,
typename = typename std::enable_if<sizeof...(Ts)+1 == DIM>::type,
typename = typename std::enable_if< typename = typename std::enable_if<
are_convertible_to<Scalar, T...>::value>::type> are_convertible_to<Scalar, T, Ts...>::value>::type>
constexpr VectorT(T... vs) : values_ { {static_cast<Scalar>(vs)...} } { constexpr VectorT(T v, Ts... vs) : values_ { {static_cast<Scalar>(v), static_cast<Scalar>(vs)...} } {
static_assert(sizeof...(T) == DIM, static_assert(sizeof...(Ts)+1 == DIM,
"Invalid number of components specified in constructor."); "Invalid number of components specified in constructor.");
static_assert(are_convertible_to<Scalar, T...>::value, static_assert(are_convertible_to<Scalar, T, Ts...>::value,
"Not all components are convertible to Scalar."); "Not all components are convertible to Scalar.");
} }
@@ -367,8 +369,7 @@ class VectorT {
auto operator% (const VectorT<OtherScalar, DIM> &_rhs) const -> auto operator% (const VectorT<OtherScalar, DIM> &_rhs) const ->
typename std::enable_if<DIM == 3, typename std::enable_if<DIM == 3,
VectorT<decltype((*this)[0] * _rhs[0] - VectorT<decltype((*this)[0] * _rhs[0] -
(*this)[0] * _rhs[0]), (*this)[0] * _rhs[0]), DIM>>::type {
DIM>>::type {
return { return {
values_[1] * _rhs[2] - values_[2] * _rhs[1], values_[1] * _rhs[2] - values_[2] * _rhs[1],
values_[2] * _rhs[0] - values_[0] * _rhs[2], values_[2] * _rhs[0] - values_[0] * _rhs[2],