diff --git a/libs/main/containers/picontainers.h b/libs/main/containers/picontainers.h index 014ddfe6..1d989b65 100644 --- a/libs/main/containers/picontainers.h +++ b/libs/main/containers/picontainers.h @@ -43,6 +43,7 @@ # include #endif #include +#include #include #include #ifndef PIP_MEMALIGN_BYTES diff --git a/libs/main/math/pigeometry.h b/libs/main/math/pigeometry.h index 3a5b75cd..ad2df750 100644 --- a/libs/main/math/pigeometry.h +++ b/libs/main/math/pigeometry.h @@ -28,6 +28,7 @@ template class PIP_EXPORT PIPoint { + static_assert(std::is_arithmetic::value, "Type must be arithmetic"); public: Type x; Type y; @@ -75,6 +76,7 @@ typedef PIPoint PIPointd; template class PIP_EXPORT PIRect { + static_assert(std::is_arithmetic::value, "Type must be arithmetic"); public: Type x0; Type y0; diff --git a/libs/main/math/pimathbase.h b/libs/main/math/pimathbase.h index d33482b7..0841ac4c 100644 --- a/libs/main/math/pimathbase.h +++ b/libs/main/math/pimathbase.h @@ -131,6 +131,7 @@ inline PIVector abs(const PIVector & v) { template bool OLS_Linear(const PIVector > & input, T * out_a, T * out_b) { + static_assert(std::is_arithmetic::value, "Type must be arithmetic"); if (input.size_s() < 2) return false; int n = input.size_s(); @@ -154,6 +155,7 @@ bool OLS_Linear(const PIVector > & input, T * out_a, T * out_b) { template bool WLS_Linear(const PIVector > & input, const PIVector & weights, T * out_a, T * out_b) { + static_assert(std::is_arithmetic::value, "Type must be arithmetic"); if (input.size_s() < 2) return false; if (input.size_s() != weights.size_s()) diff --git a/libs/main/math/pimathmatrix.h b/libs/main/math/pimathmatrix.h index 07f27863..676a4486 100644 --- a/libs/main/math/pimathmatrix.h +++ b/libs/main/math/pimathmatrix.h @@ -30,6 +30,7 @@ template inline bool _PIMathMatrixNullCompare(const T v) { + static_assert(std::is_floating_point::value, "Type must be floating point"); return (piAbs(v) < T(1E-200)); } @@ -59,6 +60,9 @@ class PIP_EXPORT PIMathMatrixT { typedef PIMathMatrixT _CMatrixI; typedef PIMathVectorT _CMCol; typedef PIMathVectorT _CMRow; + static_assert(std::is_arithmetic::value, "Type must be arithmetic"); + static_assert(Rows > 0, "Row count must be > 0"); + static_assert(Cols > 0, "Column count must be > 0"); public: PIMathMatrixT() {resize(Rows, Cols);} PIMathMatrixT(const PIVector & val) {resize(Rows, Cols); int i = 0; PIMM_FOR_I_WB(r, c) m[r][c] = val[i++];} @@ -156,10 +160,7 @@ public: } _CMatrix & invert(bool * ok = 0) { - if (Cols != Rows) { - if (ok != 0) *ok = false; - return *this; - } + static_assert(Cols == Rows, "Only square matrix invertable"); _CMatrix mtmp = _CMatrix::identity(), smat(*this); bool ndet; uint crow; diff --git a/libs/main/math/pimathvector.h b/libs/main/math/pimathvector.h index ef7d834e..7c4a9b41 100644 --- a/libs/main/math/pimathvector.h +++ b/libs/main/math/pimathvector.h @@ -36,6 +36,8 @@ class PIMathMatrixT; template class PIP_EXPORT PIMathVectorT { typedef PIMathVectorT _CVector; + static_assert(std::is_arithmetic::value, "Type must be arithmetic"); + static_assert(Size > 0, "Size count must be > 0"); public: PIMathVectorT() {resize();} PIMathVectorT(const PIVector & val) {resize(); PIMV_FOR(i, 0) c[i] = val[i];} diff --git a/libs/main/math/pistatistic.h b/libs/main/math/pistatistic.h index d4e70997..8d731842 100644 --- a/libs/main/math/pistatistic.h +++ b/libs/main/math/pistatistic.h @@ -27,6 +27,7 @@ template class PIStatistic { + static_assert(std::is_arithmetic::value, "Type must be arithmetic"); public: PIStatistic() {mean = variance = skewness = kurtosis = T();}