ENH: add factory method readContents to IO containers

- useful when regular contents are to be read via an IOobject and
  returned.

  Eg,  dictionary propsDict(IOdictionary::readContents(dictIO));
  vs.  dictionary propsDict(static_cast<dictionary&&>(IOdictionary(dictIO)));

  Commonly these would have simply been constructed directly as the
  IO container:

  eg,  IOdictionary propsDict(dictIO);

  However, that style may not ensure proper move semantics for return
  types.

  Now,
  =====
      labelList decomp(labelIOList::readContents(io));
      ... something
      return decomp;
  =====

  Previously,
  =====
      labelIOList decomp(io);

      // Hope for the best...
      return decomp;

      // Or be explicit and ensure elision occurs...
      return labelList(std::move(static_cast<labelList&>(decomp)));
  =====

  Note:
       labelList list(labelIOList(io));

       looks like a good idea, but generally fails to compile
This commit is contained in:
Mark Olesen
2023-02-28 11:17:59 +01:00
parent 790a5c26f9
commit f75af788c1
20 changed files with 211 additions and 29 deletions

View File

@ -109,7 +109,11 @@ int main(int argc, char *argv[])
{
#include "setConstantRunTimeDictionaryIO.H"
IOdictionary propsDict(dictIO);
#if (OPENFOAM > 2212)
dictionary propsDict(IOdictionary::readContents(dictIO));
#else
dictionary propsDict(static_cast<dictionary&&>(IOdictionary(dictIO)));
#endif
const scalarField xvals(propsDict.lookup("x"));