From fd219ef9b0b7177f03a45b931fabecc09aaf3b86 Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Thu, 23 Nov 2017 20:39:55 +0100 Subject: [PATCH] Simplified Communicator Using .data() (C++11) --- src/tools/Communicator.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/tools/Communicator.h b/src/tools/Communicator.h index a1675b90a..ff8acf414 100644 --- a/src/tools/Communicator.h +++ b/src/tools/Communicator.h @@ -80,8 +80,7 @@ class Communicator { template <unsigned n,unsigned m> explicit Data(TensorGeneric<n,m> &p): pointer(&p), size(n*m), type(getMPIType<double>()) {} /// Init from reference to std::vector template <typename T> explicit Data(std::vector<T>&v) { - if(v.size()>0) { Data d(&v[0],v.size()); pointer=d.pointer; size=d.size; type=d.type; } - else { pointer=NULL; size=0; } + Data d(v.data(),v.size()); pointer=d.pointer; size=d.size; type=d.type; } /// Init from reference to PLMD::Matrix template <typename T> explicit Data(Matrix<T>&m ) { @@ -107,8 +106,7 @@ class Communicator { template <unsigned n,unsigned m> explicit ConstData(const TensorGeneric<n,m> *p,int s): pointer(p), size(n*m*s), type(getMPIType<double>()) {} template <unsigned n,unsigned m> explicit ConstData(const TensorGeneric<n,m> &p): pointer(&p), size(n*m), type(getMPIType<double>()) {} template <typename T> explicit ConstData(const std::vector<T>&v) { - if(v.size()>0) { ConstData d(&v[0],v.size()); pointer=d.pointer; size=d.size; type=d.type; } - else { pointer=NULL; size=0; } + ConstData d(v.data(),v.size()); pointer=d.pointer; size=d.size; type=d.type; } template <typename T> explicit ConstData(const Matrix<T>&m ) { if(m.nrows()*m.ncols()>0) { ConstData d(&m(0,0),m.nrows()*m.ncols()); pointer=d.pointer; size=d.size; type=d.type; } -- GitLab