mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -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"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user