static_assert

This commit is contained in:
2020-08-19 16:48:08 +03:00
parent ccd6a9888f
commit 05607ccf0e
6 changed files with 13 additions and 4 deletions

View File

@@ -43,6 +43,7 @@
# include <malloc.h>
#endif
#include <initializer_list>
#include <type_traits>
#include <string.h>
#include <new>
#ifndef PIP_MEMALIGN_BYTES

View File

@@ -28,6 +28,7 @@
template<typename Type>
class PIP_EXPORT PIPoint {
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
public:
Type x;
Type y;
@@ -75,6 +76,7 @@ typedef PIPoint<double> PIPointd;
template<typename Type>
class PIP_EXPORT PIRect {
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
public:
Type x0;
Type y0;

View File

@@ -131,6 +131,7 @@ inline PIVector<double> abs(const PIVector<double> & v) {
template <typename T>
bool OLS_Linear(const PIVector<PIPair<T, T> > & input, T * out_a, T * out_b) {
static_assert(std::is_arithmetic<T>::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<PIPair<T, T> > & input, T * out_a, T * out_b) {
template <typename T>
bool WLS_Linear(const PIVector<PIPair<T, T> > & input, const PIVector<T> & weights, T * out_a, T * out_b) {
static_assert(std::is_arithmetic<T>::value, "Type must be arithmetic");
if (input.size_s() < 2)
return false;
if (input.size_s() != weights.size_s())

View File

@@ -30,6 +30,7 @@
template<typename T>
inline bool _PIMathMatrixNullCompare(const T v) {
static_assert(std::is_floating_point<T>::value, "Type must be floating point");
return (piAbs(v) < T(1E-200));
}
@@ -59,6 +60,9 @@ class PIP_EXPORT PIMathMatrixT {
typedef PIMathMatrixT<Cols, Rows, Type> _CMatrixI;
typedef PIMathVectorT<Rows, Type> _CMCol;
typedef PIMathVectorT<Cols, Type> _CMRow;
static_assert(std::is_arithmetic<Type>::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<Type> & 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;

View File

@@ -36,6 +36,8 @@ class PIMathMatrixT;
template<uint Size, typename Type = double>
class PIP_EXPORT PIMathVectorT {
typedef PIMathVectorT<Size, Type> _CVector;
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
static_assert(Size > 0, "Size count must be > 0");
public:
PIMathVectorT() {resize();}
PIMathVectorT(const PIVector<Type> & val) {resize(); PIMV_FOR(i, 0) c[i] = val[i];}

View File

@@ -27,6 +27,7 @@
template <typename T>
class PIStatistic {
static_assert(std::is_arithmetic<T>::value, "Type must be arithmetic");
public:
PIStatistic() {mean = variance = skewness = kurtosis = T();}