schrodinger / maeparser

maestro file parser
MIT License
23 stars 23 forks source link

Avoid rvalue reference and move for compatibility (#61) #62

Closed e-kwsm closed 4 years ago

e-kwsm commented 4 years ago

#61 2b364d918b60e8227d99d6132e45e1593c218c96 breaks compatibility, leading to compilation failure of Open Babel:

../src/formats/maeformat.cpp: In member function ‘virtual bool OpenBabel::MAEFormat::WriteMolecule(OpenBabel::OBBase*, OpenBabel::OBConversion*)’:
../src/formats/maeformat.cpp:332:49: error: cannot bind rvalue reference of type ‘std::shared_ptr<schrodinger::mae::IndexedBlock>&&’ to lvalue of type ‘std::shared_ptr<schrodinger::mae::IndexedBlock>’
     ibm->addIndexedBlock(atom_block->getName(), atom_block);
                                                 ^~~~~~~~~~
In file included from ../external/maeparser-master/maeparser/Reader.hpp:8,
                 from ../src/formats/maeformat.cpp:33:
../external/maeparser-master/maeparser/MaeBlock.hpp:72:10: note:   initializing argument 2 of ‘void schrodinger::mae::IndexedBlockMap::addIndexedBlock(const string&, std::shared_ptr<schrodinger::mae::IndexedBlock>&&)’
     void addIndexedBlock(const std::string& name,
          ^~~~~~~~~~~~~~~
../src/formats/maeformat.cpp:333:49: error: cannot bind rvalue reference of type ‘std::shared_ptr<schrodinger::mae::IndexedBlock>&&’ to lvalue of type ‘std::shared_ptr<schrodinger::mae::IndexedBlock>’
     ibm->addIndexedBlock(bond_block->getName(), bond_block);
                                                 ^~~~~~~~~~
In file included from ../external/maeparser-master/maeparser/Reader.hpp:8,
                 from ../src/formats/maeformat.cpp:33:
../external/maeparser-master/maeparser/MaeBlock.hpp:72:10: note:   initializing argument 2 of ‘void schrodinger::mae::IndexedBlockMap::addIndexedBlock(const string&, std::shared_ptr<schrodinger::mae::IndexedBlock>&&)’
     void addIndexedBlock(const std::string& name,
          ^~~~~~~~~~~~~~~

To fix this, const reference pass by value and use move instead of rvalue reference.

d-b-w commented 4 years ago

NBD, but I think that these should at least be by value, so that they are moved if possible.

d-b-w commented 4 years ago

Thanks for this!