diff --git a/regtest/basic/rt-make-wrappers/COLVAR.reference b/regtest/basic/rt-make-wrappers/COLVAR.reference index b4d38c02e0c0b44b2d34f4261138e39d8e878ce3..1d11bf0959bca59a5690c9dc11143bc22f8726fc 100644 --- a/regtest/basic/rt-make-wrappers/COLVAR.reference +++ b/regtest/basic/rt-make-wrappers/COLVAR.reference @@ -54,3 +54,7 @@ 0.000000 0.000000 #! FIELDS time d 0.000000 0.000000 +#! FIELDS time d + 0.000000 0.000000 +#! FIELDS time d + 0.000000 0.000000 diff --git a/regtest/basic/rt-make-wrappers/main.cpp b/regtest/basic/rt-make-wrappers/main.cpp index 047ece96b60f105f106ae3c2b1c602afe9ee3ed7..e36280be43a998379d021db3fe15b6345522e93e 100644 --- a/regtest/basic/rt-make-wrappers/main.cpp +++ b/regtest/basic/rt-make-wrappers/main.cpp @@ -137,13 +137,26 @@ int main(){ testmecpp(p); } + { +// test move semantics + PLMD::Plumed p; + PLMD::Plumed q(std::move(p)); + testmecpp(q); + } + + { + PLMD::Plumed p,q; + q=std::move(p); + testmecpp(q); + } + if(PLMD::Plumed::ginitialized()) return 0; PLMD::Plumed::gcreate(); if(!PLMD::Plumed::ginitialized()) return 0; // this requires move semantics and only works with C++11 - //PLMD::Plumed fromglobal(PLMD::Plumed::global()); + PLMD::Plumed fromglobal(PLMD::Plumed::global()); // here's a workaround for plumed 2.3: - PLMD::Plumed fromglobal(plumed_global()); + //PLMD::Plumed fromglobal(plumed_global()); testmecpp(fromglobal); PLMD::Plumed::gfinalize(); if(PLMD::Plumed::ginitialized()) return 0; diff --git a/src/wrapper/Plumed.h b/src/wrapper/Plumed.h index 826bed4af67020a29e8580318261a0d449e5170f..085a48241ee3a32c477dd320984e062427bc058e 100644 --- a/src/wrapper/Plumed.h +++ b/src/wrapper/Plumed.h @@ -514,14 +514,23 @@ inline Plumed::Plumed(Plumed&& p): main(p.main), reference(p.reference) -{} +{ + p.main.p=nullptr; + p.reference=true; // make sure the moved plumed is not finalized +} inline Plumed& Plumed::operator=(Plumed&& p) { - main=p.main; - reference=p.reference; + if(this != &p) { + if(!reference) plumed_finalize(main); + main=p.main; + reference=p.reference; + p.main.p=nullptr; + p.reference=true; // make sure the moved plumed is not finalized + } return *this; } + #endif inline