Commit ef0243ba authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

static assertions

parent a8ed5f57
......@@ -26,18 +26,6 @@
namespace PLMD {
/// Small auxiliary class.
/// I use it to test a few things that I am scary of and could introduce bugs.
/// It checks at startup that Tensor satifies some requirement so as to allow
/// accessing a vector of tensors as a 9 times longer array of doubles.
static class TensorChecks {
public:
TensorChecks() {
if(sizeof(Tensor)==9*sizeof(double)) return;
plumed_merror("sizeof(Tensor)!=9*sizeof(double). PLUMED cannot work properly in these conditions.");
}
} checks;
void TensorGenericAux::local_dsyevr(const char *jobz, const char *range, const char *uplo, int *n,
double *a, int *lda, double *vl, double *vu, int *
il, int *iu, double *abstol, int *m, double *w,
......
......@@ -561,6 +561,7 @@ void diagMatSym(const TensorGeneric<n,n>&mat,VectorGeneric<m>&evals,TensorGeneri
}
}
static_assert(sizeof(Tensor)==9*sizeof(double), "code cannot work if this is not satisfied");
}
......
......@@ -20,26 +20,3 @@
along with plumed. If not, see <http://www.gnu.org/licenses/>.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
#include "Vector.h"
#include "Exception.h"
#include <cmath>
namespace PLMD {
/// Small auxiliary class.
/// I use it to test a few things that I am scary of and could introduce bugs.
/// It checks at startup that Vector satifies some requirement so as to allow
/// accessing a vector of tensors as a 3 times longer array of doubles.
static class VectorChecks {
public:
VectorChecks() {
if( sizeof(VectorGeneric<2>)==2*sizeof(double)
&& sizeof(VectorGeneric<3>)==3*sizeof(double)
&& sizeof(VectorGeneric<4>)==4*sizeof(double)) return;
plumed_merror("sizeof(VectorGeneric<x>)!=x*sizeof(double). PLUMED cannot work properly in these conditions.");
}
} checks;
}
......@@ -333,6 +333,10 @@ typedef VectorGeneric<5> Vector5d;
/// Alias for three dimensional vectors
typedef Vector3d Vector;
static_assert(sizeof(VectorGeneric<2>)==2*sizeof(double), "code cannot work if this is not satisfied");
static_assert(sizeof(VectorGeneric<3>)==3*sizeof(double), "code cannot work if this is not satisfied");
static_assert(sizeof(VectorGeneric<4>)==4*sizeof(double), "code cannot work if this is not satisfied");
}
#endif
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment