static_assert
This commit is contained in:
@@ -43,6 +43,7 @@
|
|||||||
# include <malloc.h>
|
# include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
#include <type_traits>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <new>
|
#include <new>
|
||||||
#ifndef PIP_MEMALIGN_BYTES
|
#ifndef PIP_MEMALIGN_BYTES
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
class PIP_EXPORT PIPoint {
|
class PIP_EXPORT PIPoint {
|
||||||
|
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
|
||||||
public:
|
public:
|
||||||
Type x;
|
Type x;
|
||||||
Type y;
|
Type y;
|
||||||
@@ -75,6 +76,7 @@ typedef PIPoint<double> PIPointd;
|
|||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
class PIP_EXPORT PIRect {
|
class PIP_EXPORT PIRect {
|
||||||
|
static_assert(std::is_arithmetic<Type>::value, "Type must be arithmetic");
|
||||||
public:
|
public:
|
||||||
Type x0;
|
Type x0;
|
||||||
Type y0;
|
Type y0;
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ inline PIVector<double> abs(const PIVector<double> & v) {
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool OLS_Linear(const PIVector<PIPair<T, T> > & input, T * out_a, T * out_b) {
|
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)
|
if (input.size_s() < 2)
|
||||||
return false;
|
return false;
|
||||||
int n = input.size_s();
|
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>
|
template <typename T>
|
||||||
bool WLS_Linear(const PIVector<PIPair<T, T> > & input, const PIVector<T> & weights, T * out_a, T * out_b) {
|
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)
|
if (input.size_s() < 2)
|
||||||
return false;
|
return false;
|
||||||
if (input.size_s() != weights.size_s())
|
if (input.size_s() != weights.size_s())
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline bool _PIMathMatrixNullCompare(const T v) {
|
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));
|
return (piAbs(v) < T(1E-200));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +60,9 @@ class PIP_EXPORT PIMathMatrixT {
|
|||||||
typedef PIMathMatrixT<Cols, Rows, Type> _CMatrixI;
|
typedef PIMathMatrixT<Cols, Rows, Type> _CMatrixI;
|
||||||
typedef PIMathVectorT<Rows, Type> _CMCol;
|
typedef PIMathVectorT<Rows, Type> _CMCol;
|
||||||
typedef PIMathVectorT<Cols, Type> _CMRow;
|
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:
|
public:
|
||||||
PIMathMatrixT() {resize(Rows, Cols);}
|
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++];}
|
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) {
|
_CMatrix & invert(bool * ok = 0) {
|
||||||
if (Cols != Rows) {
|
static_assert(Cols == Rows, "Only square matrix invertable");
|
||||||
if (ok != 0) *ok = false;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
_CMatrix mtmp = _CMatrix::identity(), smat(*this);
|
_CMatrix mtmp = _CMatrix::identity(), smat(*this);
|
||||||
bool ndet;
|
bool ndet;
|
||||||
uint crow;
|
uint crow;
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ class PIMathMatrixT;
|
|||||||
template<uint Size, typename Type = double>
|
template<uint Size, typename Type = double>
|
||||||
class PIP_EXPORT PIMathVectorT {
|
class PIP_EXPORT PIMathVectorT {
|
||||||
typedef PIMathVectorT<Size, Type> _CVector;
|
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:
|
public:
|
||||||
PIMathVectorT() {resize();}
|
PIMathVectorT() {resize();}
|
||||||
PIMathVectorT(const PIVector<Type> & val) {resize(); PIMV_FOR(i, 0) c[i] = val[i];}
|
PIMathVectorT(const PIVector<Type> & val) {resize(); PIMV_FOR(i, 0) c[i] = val[i];}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class PIStatistic {
|
class PIStatistic {
|
||||||
|
static_assert(std::is_arithmetic<T>::value, "Type must be arithmetic");
|
||||||
public:
|
public:
|
||||||
PIStatistic() {mean = variance = skewness = kurtosis = T();}
|
PIStatistic() {mean = variance = skewness = kurtosis = T();}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user