From 7c60c80edd09409c8ce9d7d2313f75e8f9a7c874 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 26 Jan 2023 11:24:25 +0100 Subject: [PATCH] ENH: new/revised emplace_back() [for DynamicList/List/PtrDynList/PtrList] - returns reference as per C++17 std::vector STYLE: drop unused, redundant DynamicField remove() method --- .../test/DynamicField/Test-DynamicField.C | 16 ++++---- .../test/DynamicList/Test-DynamicList.C | 27 +++++++------ applications/test/Function1/Test-Function1.C | 6 +-- applications/test/ListOps/Test-ListOps.C | 2 +- .../Test-PatchEdgeFaceWave.C | 12 ++---- applications/test/PtrList/Test-PtrList.C | 38 +++++++++---------- .../test/UIndirectList/Test-UIndirectList.C | 5 ++- applications/test/cstring/Test-cstring.C | 10 ++--- .../Test-dynamicIndexedOctree.C | 13 ++++--- .../test/dynamicLibrary/Test-dynamicLibrary.C | 4 +- .../test/globalIndex/Test-globalIndex.C | 4 +- applications/test/instant/Test-instant.C | 32 ++++++++-------- .../test/labelRanges/Test-labelRanges.C | 10 ++--- .../test/patchRegion/Test-patchRegion.C | 7 +--- .../Test-reconstructedDistanceFunction.C | 4 +- applications/test/router/router.C | 4 +- applications/test/tokenize/Test-tokenize.C | 2 +- applications/test/wordRe/Test-wordRe.C | 2 +- .../Lists/DynamicList/DynamicList.H | 5 +++ .../Lists/DynamicList/DynamicListI.H | 17 +++++++++ src/OpenFOAM/containers/Lists/List/List.H | 6 +++ src/OpenFOAM/containers/Lists/List/ListI.H | 19 +++++++++- .../PtrLists/PtrDynList/PtrDynList.H | 5 ++- .../PtrLists/PtrDynList/PtrDynListI.H | 3 +- .../containers/PtrLists/PtrList/PtrList.H | 7 ++-- .../containers/PtrLists/PtrList/PtrListI.H | 5 ++- .../fields/Fields/DynamicField/DynamicField.H | 12 +++--- .../Fields/DynamicField/DynamicFieldI.H | 37 +++++++++--------- 28 files changed, 179 insertions(+), 135 deletions(-) diff --git a/applications/test/DynamicField/Test-DynamicField.C b/applications/test/DynamicField/Test-DynamicField.C index 41cc07eede..ba5825314f 100644 --- a/applications/test/DynamicField/Test-DynamicField.C +++ b/applications/test/DynamicField/Test-DynamicField.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation + Copyright (C) 2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -52,28 +53,29 @@ int main(int argc, char *argv[]) Info << "testField:" << testField << endl; - testField.append(vector(0.5, 4.8, 6.2)); + testField.emplace_back(0.5, 4.8, 6.2); Info << "testField after appending:" << testField << endl; - testField.append(vector(2.7, 2.3, 6.1)); + testField.emplace_back(2.7, 2.3, 6.1); Info << "testField after appending:" << testField << endl; - vector elem = testField.remove(); + vector elem = testField.back(); + testField.pop_back(); Info << "removed element:" << elem << endl; Info << "testField:" << testField << endl; - testField.append(vector(3.0, 1.3, 9.2)); + testField.emplace_back(3.0, 1.3, 9.2); Info << "testField:" << testField << endl; - testField.setSize(10, vector(1.5, 0.6, -1.0)); + testField.resize(10, vector(1.5, 0.6, -1.0)); Info << "testField after setSize:" << testField << endl; - testField.append(testField2); + testField.push_back(testField2); Info << "testField after appending testField2:" << testField << endl; @@ -87,7 +89,7 @@ int main(int argc, char *argv[]) testField.clear(); - testField.append(vector(3.0, 1.3, 9.2)); + testField.emplace_back(3.0, 1.3, 9.2); Info << "testField after clear and append:" << testField << endl; diff --git a/applications/test/DynamicList/Test-DynamicList.C b/applications/test/DynamicList/Test-DynamicList.C index 7765269cae..ce6fb4b210 100644 --- a/applications/test/DynamicList/Test-DynamicList.C +++ b/applications/test/DynamicList/Test-DynamicList.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -140,7 +140,7 @@ int main(int argc, char *argv[]) { 0, 1, 2, 3, 4 }; - dlA.append({ 5, 6 }); + dlA.push_back({ 5, 6 }); dlA = { 1, 2, 4 }; DynamicList