From e42c2281554ed6a2a54de611d86d6a0349516bbf Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 8 Feb 2018 08:53:14 +0100 Subject: [PATCH] ENH: cleanup List constructors (issue #725) - add copy construct from UList - remove copy construct from dissimilar types. This templated constructor was too generous in what it accepted. For the special cases where a copy constructor is required with a change in the data type, now use the createList factory method, which accepts a unary operator. Eg, auto scalars = scalarList::createList ( labels, [](const label& val){ return 1.5*val; } ); --- applications/test/List/Test-List.C | 107 +++++++++ .../manipulation/checkMesh/checkGeometry.C | 12 +- .../moveDynamicMesh/moveDynamicMesh.C | 6 +- .../foamFormatConvert/foamFormatConvert.C | 30 ++- src/OpenFOAM/containers/Lists/List/List.C | 216 +++++++++++++----- src/OpenFOAM/containers/Lists/List/List.H | 76 ++++-- src/OpenFOAM/containers/Lists/List/ListI.H | 39 ++-- .../containers/Lists/ListOps/ListOps.C | 1 - src/OpenFOAM/db/Time/TimeIO.C | 4 +- src/OpenFOAM/primitives/ints/label/label.H | 36 ++- 10 files changed, 398 insertions(+), 129 deletions(-) diff --git a/applications/test/List/Test-List.C b/applications/test/List/Test-List.C index ec4ec9e5a1..945b0e9998 100644 --- a/applications/test/List/Test-List.C +++ b/applications/test/List/Test-List.C @@ -48,6 +48,23 @@ See also #include #include +#include + +namespace Foam +{ + +// Verify inheritance +class MyStrings +: + public List +{ +public: + + using List::List; +}; + +} // end namespace Foam + using namespace Foam; @@ -66,6 +83,14 @@ void testFind(const T& val, const ListType& lst) } +void printMyString(const UList& lst) +{ + MyStrings slist2(lst); + + Info<::createList + ( + labels, + [](const label& val){ return scalar(1.5*val); } + ); + Info<< "scalars: " << flatOutput(scalars) << endl; + } + + { + auto vectors = List::createList + ( + labels, + [](const label& val){ return vector(1.2*val, -1.2*val, 0); } + ); + Info<< "vectors: " << flatOutput(vectors) << endl; + } + + { + auto longs = List::createList + ( + labels, + [](const label& val){ return val; } + ); + Info<< "longs: " << flatOutput(longs) << endl; + } + { + auto negs = List