diff --git a/applications/test/PtrList/Test-PtrList.C b/applications/test/PtrList/Test-PtrList.C index f2f2777b67..b170ba92c8 100644 --- a/applications/test/PtrList/Test-PtrList.C +++ b/applications/test/PtrList/Test-PtrList.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -278,7 +278,7 @@ int main(int argc, char *argv[]) llist1.insert(new Scalar(200)); llist1.insert(new Scalar(300)); - DLPtrList::const_iterator citer = llist1.begin(); + auto citer = llist1.begin(); Info<< *citer << endl; Info<< typeid(*citer).name() << endl; @@ -324,15 +324,18 @@ int main(int argc, char *argv[]) list1.set(i, new Scalar(1.3*i)); } + Info<<"Emplace set " << list2.size() << " values" << nl; forAll(list2, i) { - list2.set(i, new Scalar(10 + 1.3*i)); + list2.emplace(i, (10 + 1.3*i)); } for (label i = 0; i < 5; ++i) { listApp.append(new Scalar(1.3*i)); } + listApp.emplace_append(100); + Info<< nl <<"list1: " << list1 << nl @@ -529,8 +532,8 @@ int main(int argc, char *argv[]) } PtrList planes; - planes.append(new plane(vector::one, vector::one)); - planes.append(new plane(vector(1,2,3), vector::one)); + planes.emplace_append(vector::one, vector::one); + planes.emplace_append(vector(1,2,3), vector::one); Info<< nl << "appended values" << nl; for (const plane& p : planes) @@ -543,15 +546,18 @@ int main(int argc, char *argv[]) PtrDynList dynPlanes; { - dynPlanes.append(new plane(vector::one, vector::one)); - dynPlanes.append(new plane(vector(1,2,3), vector::one)); + dynPlanes.emplace_append(vector::one, vector::one); + dynPlanes.emplace_append(vector(1,2,3), vector::one); dynPlanes.append(nullptr); dynPlanes.set(6, new plane(vector(2,2,1), vector::one)); dynPlanes.set(10, new plane(vector(4,5,6), vector::one)); + + dynPlanes.emplace(12, vector(3,2,1), vector::one); + dynPlanes.emplace_append(Zero, vector::one); } - Info<< nl << "PtrList: "; + Info<< nl << "PtrDynList: "; report(Info, dynPlanes, true); dynPlanes.resize(9); diff --git a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H index a3a5290bbf..d30b06301a 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H +++ b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -43,6 +43,8 @@ SourceFiles #include "PtrList.H" #include +#include +#include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -50,7 +52,6 @@ namespace Foam { // Forward Declarations - template class PtrDynList; /*---------------------------------------------------------------------------*\ @@ -107,6 +108,11 @@ public: //- Size of the underlying storage. inline label capacity() const noexcept; + //- Return const pointer to element (if set) or nullptr, + // with bounds checking. + // The return value can be tested as a bool. + inline const T* set(const label i) const; + // Edit @@ -145,14 +151,27 @@ public: // \return the number of non-null entries inline label squeezeNull(); + //- Construct and append an element to the end of the list + template + inline void emplace_append(Args&&... args); + //- Append an element to the end of the list inline void append(T* ptr); //- Move append an element to the end of the list - inline void append(const autoPtr& aptr); + inline void append(autoPtr& ptr); + + //- Move append an element to the end of the list + inline void append(autoPtr&& ptr); + + //- Move append an element to the end of the list + inline void append(std::unique_ptr&& ptr); //- Move or clone append a tmp to the end of the list - inline void append(const tmp& tptr); + inline void append(const refPtr& ptr); + + //- Move or clone append a tmp to the end of the list + inline void append(const tmp& ptr); //- Move append another list to the end of this list. inline void append(PtrList&& other); @@ -164,18 +183,27 @@ public: //- Remove and return the top element inline autoPtr remove(); - //- Return const pointer to element (if set) or nullptr. - // The return value can be tested as a bool. - inline const T* set(const label i) const; + //- Construct and set an element + template + inline autoPtr emplace(const label i, Args&&... args); //- Set element to given pointer and return old element (can be null) inline autoPtr set(const label i, T* ptr); //- Set element to given autoPtr and return old element - inline autoPtr set(const label i, const autoPtr& aptr); + inline autoPtr set(const label i, autoPtr& ptr); + + //- Set element to given autoPtr and return old element + inline autoPtr set(const label i, autoPtr&& ptr); + + //- Set element to given pointer and return old element + inline autoPtr set(const label i, std::unique_ptr&& ptr); + + //- Set element to given refPtr and return old element + inline autoPtr set(const label i, const refPtr& ptr); //- Set element to given tmp and return old element - inline autoPtr set(const label i, const tmp& tptr); + inline autoPtr set(const label i, const tmp& ptr); //- Reorder elements. Reordering must be unique (ie, shuffle). inline void reorder(const labelUList& oldToNew); diff --git a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H index d6845719d8..a75bbff861 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H +++ b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,6 +26,7 @@ License \*---------------------------------------------------------------------------*/ #include "autoPtr.H" +#include "refPtr.H" #include "tmp.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -98,6 +99,13 @@ inline Foam::label Foam::PtrDynList::capacity() const noexcept } +template +inline const T* Foam::PtrDynList::set(const label i) const +{ + return (i >= 0 && i < PtrList::size()) ? PtrList::get(i) : nullptr; +} + + template inline void Foam::PtrDynList::setCapacity(const label nElem) { @@ -151,13 +159,7 @@ inline void Foam::PtrDynList::resize(const label newLen) // Truncation frees old pointers for (label i=newLen; i::squeezeNull() } +template +template +inline void Foam::PtrDynList::emplace_append(Args&&... args) +{ + this->append(new T(std::forward(args)...)); +} + + template inline void Foam::PtrDynList::append(T* ptr) { @@ -237,16 +247,37 @@ inline void Foam::PtrDynList::append(T* ptr) template -inline void Foam::PtrDynList::append(const autoPtr& aptr) +inline void Foam::PtrDynList::append(autoPtr& ptr) { - this->append(const_cast&>(aptr).release()); + this->append(ptr.release()); } template -inline void Foam::PtrDynList::append(const tmp& tptr) +inline void Foam::PtrDynList::append(autoPtr&& ptr) { - this->append(tptr.ptr()); + this->append(ptr.release()); +} + + +template +inline void Foam::PtrDynList::append(std::unique_ptr&& ptr) +{ + this->append(ptr.release()); +} + + +template +inline void Foam::PtrDynList::append(const refPtr& ptr) +{ + this->append(ptr.ptr()); +} + + +template +inline void Foam::PtrDynList::append(const tmp& ptr) +{ + this->append(ptr.ptr()); } @@ -308,9 +339,14 @@ inline Foam::autoPtr Foam::PtrDynList::remove() template -inline const T* Foam::PtrDynList::set(const label i) const +template +inline Foam::autoPtr Foam::PtrDynList::emplace +( + const label i, + Args&&... args +) { - return (i >= 0 && i < PtrList::size()) ? PtrList::set(i) : nullptr; + return this->set(i, new T(std::forward(args)...)); } @@ -334,10 +370,10 @@ template inline Foam::autoPtr Foam::PtrDynList::set ( const label i, - const autoPtr& aptr + autoPtr& ptr ) { - return this->set(i, const_cast&>(aptr).release()); + return this->set(i, ptr.release()); } @@ -345,10 +381,43 @@ template inline Foam::autoPtr Foam::PtrDynList::set ( const label i, - const tmp& tptr + autoPtr&& ptr ) { - return this->set(i, tptr.ptr()); + return this->set(i, ptr.release()); +} + + +template +inline Foam::autoPtr Foam::PtrDynList::set +( + const label i, + std::unique_ptr&& ptr +) +{ + return this->set(i, ptr.release()); +} + + +template +inline Foam::autoPtr Foam::PtrDynList::set +( + const label i, + const refPtr& ptr +) +{ + return this->set(i, ptr.ptr()); +} + + +template +inline Foam::autoPtr Foam::PtrDynList::set +( + const label i, + const tmp& ptr +) +{ + return this->set(i, ptr.ptr()); } diff --git a/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H b/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H index a30f5b7bed..494eccd484 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H +++ b/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -48,6 +48,8 @@ SourceFiles #include "UPtrList.H" #include "SLPtrListFwd.H" +#include +#include // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -55,14 +57,12 @@ namespace Foam { // Forward Declarations - template class autoPtr; +template class refPtr; template class tmp; template class PtrList; - template Istream& operator>>(Istream& is, PtrList& list); - /*---------------------------------------------------------------------------*\ Class PtrList Declaration \*---------------------------------------------------------------------------*/ @@ -87,7 +87,7 @@ public: // Constructors - //- Construct null + //- Default construct inline constexpr PtrList() noexcept; //- Construct with specified size, each element initialized to nullptr @@ -130,6 +130,17 @@ public: template PtrList clone(Args&&... args) const; + + // Access + + //- Return const pointer to element (can be nullptr), + // without bounds checking. + // The return value can also be tested as a bool. + const T* set(const label i) const { return UPtrList::set(i); } + + + // Edit + //- Clear the PtrList. Delete allocated entries and set size to zero. inline void clear(); @@ -140,42 +151,58 @@ public: //- Same as resize() inline void setSize(const label newLen); + //- Construct and append an element to the end of the list + template + inline void emplace_append(Args&&... args); + //- Append an element to the end of the list inline void append(T* ptr); //- Move append an element to the end of the list - inline void append(autoPtr& aptr); + inline void append(autoPtr& ptr); //- Move append an element to the end of the list - inline void append(autoPtr&& aptr); + inline void append(autoPtr&& ptr); + + //- Move append an element to the end of the list + inline void append(std::unique_ptr&& ptr); + + //- Move or clone append a refPtr to the end of the list + inline void append(const refPtr& ptr); //- Move or clone append a tmp to the end of the list - inline void append(const tmp& tptr); + inline void append(const tmp& ptr); - //- Transfer into this list and annul the argument list - inline void transfer(PtrList& list); - - //- Return const pointer to element (if set) or nullptr. - // The return value can be tested as a bool. - inline const T* set(const label i) const; + //- Construct and set an element + template + inline autoPtr emplace(const label i, Args&&... args); //- Set element to given pointer and return old element (can be null) // No-op if the new pointer value is identical to the current content. inline autoPtr set(const label i, T* ptr); //- Set element to given autoPtr and return old element - inline autoPtr set(const label i, autoPtr& aptr); + inline autoPtr set(const label i, autoPtr& ptr); //- Set element to given autoPtr and return old element - inline autoPtr set(const label i, autoPtr&& aptr); + inline autoPtr set(const label i, autoPtr&& ptr); + + //- Set element to given unique_ptr and return old element + inline autoPtr set(const label i, std::unique_ptr&& ptr); + + //- Set element to given refPtr and return old element + inline autoPtr set(const label i, const refPtr& ptr); //- Set element to given tmp and return old element - inline autoPtr set(const label i, const tmp& tptr); + inline autoPtr set(const label i, const tmp& ptr); //- Release ownership of the pointer at the given position. // Out of bounds addressing is a no-op and returns nullptr. inline autoPtr release(const label i); + //- Transfer into this list and annul the argument list + inline void transfer(PtrList& list); + // Member Operators @@ -192,7 +219,6 @@ public: //- Read from Istream, discarding contents of existing list friend Istream& operator>> (Istream& is, PtrList& list); - }; diff --git a/src/OpenFOAM/containers/PtrLists/PtrList/PtrListI.H b/src/OpenFOAM/containers/PtrLists/PtrList/PtrListI.H index 37ef1caa57..a8a84aa8b4 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrList/PtrListI.H +++ b/src/OpenFOAM/containers/PtrLists/PtrList/PtrListI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,6 +27,7 @@ License \*---------------------------------------------------------------------------*/ #include "autoPtr.H" +#include "refPtr.H" #include "tmp.H" // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // @@ -71,14 +72,10 @@ inline Foam::PtrList::PtrList(PtrList&& list) template inline Foam::PtrList::PtrList(UList& list) : - UPtrList(list.size()) + UPtrList(list) { - // Take ownership of the pointer - forAll(list, i) - { - set(i, list[i]); - list[i] = nullptr; - } + // Took ownership of the pointers + list = reinterpret_cast(0); } @@ -111,6 +108,14 @@ inline void Foam::PtrList::setSize(const label newLen) } +template +template +inline void Foam::PtrList::emplace_append(Args&&... args) +{ + UPtrList::append(new T(std::forward(args)...)); +} + + template inline void Foam::PtrList::append(T* ptr) { @@ -119,58 +124,115 @@ inline void Foam::PtrList::append(T* ptr) template -inline void Foam::PtrList::append(autoPtr& aptr) +inline void Foam::PtrList::append(autoPtr& ptr) { - UPtrList::append(aptr.release()); + UPtrList::append(ptr.release()); } template -inline void Foam::PtrList::append(autoPtr&& aptr) +inline void Foam::PtrList::append(autoPtr&& ptr) { - UPtrList::append(aptr.release()); + UPtrList::append(ptr.release()); } template -inline void Foam::PtrList::append(const tmp& tptr) +inline void Foam::PtrList::append(std::unique_ptr&& ptr) { - UPtrList::append(tptr.ptr()); + UPtrList::append(ptr.release()); } template -inline const T* Foam::PtrList::set(const label i) const +inline void Foam::PtrList::append(const refPtr& ptr) { - return UPtrList::set(i); + UPtrList::append(ptr.ptr()); +} + + +template +inline void Foam::PtrList::append(const tmp& ptr) +{ + UPtrList::append(ptr.ptr()); +} + + +template +template +inline Foam::autoPtr Foam::PtrList::emplace +( + const label i, + Args&&... args +) +{ + return set(i, new T(std::forward(args)...)); } template inline Foam::autoPtr Foam::PtrList::set(const label i, T* ptr) { + // UPtrList::set returns a nullptr if trying to set with the same + // pointer (again). This prevents the autoPtr from managing the + // memory (avoids possible double deletion). + return autoPtr(UPtrList::set(i, ptr)); } template -inline Foam::autoPtr Foam::PtrList::set(const label i, autoPtr& aptr) +inline Foam::autoPtr Foam::PtrList::set +( + const label i, + autoPtr& ptr +) { - return set(i, aptr.release()); + return set(i, ptr.release()); } template -inline Foam::autoPtr Foam::PtrList::set(const label i, autoPtr&& aptr) +inline Foam::autoPtr Foam::PtrList::set +( + const label i, + autoPtr&& ptr +) { - return set(i, aptr.release()); + return set(i, ptr.release()); } template -inline Foam::autoPtr Foam::PtrList::set(const label i, const tmp& tptr) +inline Foam::autoPtr Foam::PtrList::set +( + const label i, + std::unique_ptr&& ptr +) { - return set(i, tptr.ptr()); + return set(i, ptr.release()); +} + + +template +inline Foam::autoPtr Foam::PtrList::set +( + const label i, + const refPtr& ptr +) +{ + return set(i, ptr.ptr()); +} + + +template +inline Foam::autoPtr Foam::PtrList::set +( + const label i, + const tmp& ptr +) +{ + return set(i, ptr.ptr()); } diff --git a/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetail.H b/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetail.H index 9268b1ded5..92904a9e08 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetail.H +++ b/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetail.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,9 +31,13 @@ Description This class is considered implementation detail and should not normally be used other than by OpenFOAM container classes. + It stores a list of pointers, but makes leaves memory management + to the caller or sub-class. + The free() method can be used explicitly as required. + SourceFiles - PtrListDetailI.H PtrListDetail.C + PtrListDetailI.H PtrListDetailIO.C \*---------------------------------------------------------------------------*/ @@ -47,10 +51,6 @@ SourceFiles namespace Foam { - -// Forward declarations -class Ostream; - namespace Detail { @@ -67,11 +67,15 @@ public: // Constructors - //- Construct null + //- Default construct inline constexpr PtrListDetail() noexcept; //- Construct with specified size, each element initialized to nullptr - inline PtrListDetail(const label len); + inline explicit PtrListDetail(const label len); + + //- Copy a list of pointers. + // The caller is responsible for memory management. + inline explicit PtrListDetail(const UList& list); //- Copy construct (shallow copies addresses) inline PtrListDetail(const PtrListDetail& list); @@ -125,7 +129,6 @@ public: void setSize(const label) = delete; void setSize(const label, const T&) = delete; void setSize(const label, const T*) = delete; - }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetailI.H b/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetailI.H index 99e8670604..42fe47f886 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetailI.H +++ b/src/OpenFOAM/containers/PtrLists/PtrListDetail/PtrListDetailI.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -41,6 +41,16 @@ inline Foam::Detail::PtrListDetail::PtrListDetail(const label len) {} +template +inline Foam::Detail::PtrListDetail::PtrListDetail +( + const UList& list +) +: + List(list) +{} + + template inline Foam::Detail::PtrListDetail::PtrListDetail ( diff --git a/src/OpenFOAM/containers/PtrLists/PtrListOps/PtrListOpsTemplates.C b/src/OpenFOAM/containers/PtrLists/PtrListOps/PtrListOpsTemplates.C index 7d5471ebb2..0feeb4bba8 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrListOps/PtrListOpsTemplates.C +++ b/src/OpenFOAM/containers/PtrLists/PtrListOps/PtrListOpsTemplates.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -79,7 +79,7 @@ void Foam::sortedOrder template void Foam::sort(UPtrList& list) { - labelList order(input.size()); + labelList order(list.size()); sortedOrder(list, order); list.sortOrder(order, false); // false = allow nullptr } @@ -88,7 +88,7 @@ void Foam::sort(UPtrList& list) template void Foam::sort(UPtrList& list, const Compare& comp) { - labelList order(input.size()); + labelList order(list.size()); sortedOrder(list, order, comp); list.sortOrder(order, false); // false = allow nullptr } diff --git a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H index daac5d7cea..4dd0662854 100644 --- a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H +++ b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrList.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -59,13 +59,10 @@ namespace Foam { // Forward Declarations - template class PtrList; template class UPtrList; - template Ostream& operator<<(Ostream& os, const UPtrList& list); - /*---------------------------------------------------------------------------*\ Class UPtrList Declaration \*---------------------------------------------------------------------------*/ @@ -109,7 +106,7 @@ public: // Constructors - //- Construct null + //- Default construct inline constexpr UPtrList() noexcept; //- Construct with specified size, each element initialized to nullptr @@ -126,9 +123,12 @@ public: //- Shallow copy from PtrList. // The argument is non-const to reflect that the UPtrList can change - // the values (but not the addresses) of the original list. + // the values (not the addresses) within the original list. explicit UPtrList(PtrList& list); + //- Construct from UList of pointers + inline explicit UPtrList(const UList& list); + //- Construct from UList, taking the address of each list element // The argument is non-const to reflect that the UPtrList can change // the values of the original list. @@ -157,6 +157,11 @@ public: //- Return reference to the last element of the list inline const T& last() const; + //- Return const pointer to element (can be nullptr), + // without bounds checking. + // The return value can also be tested as a bool. + const T* set(const label i) const { return ptrs_[i]; } + // Edit @@ -183,10 +188,6 @@ public: //- Transfer contents into this list and annul the argument inline void transfer(UPtrList& list); - //- Return const pointer to element (if set) or nullptr. - // The return value can be tested as a bool. - inline const T* set(const label i) const; - //- Set element to specified pointer and return the old list element, //- which can be a nullptr. // No-op if the new pointer value is identical to the current content. @@ -211,7 +212,7 @@ public: //- Return reference to the element inline T& operator[](const label i); - //- Return const pointer to the element + //- Return const pointer to the element. inline const T* operator()(const label i) const; //- Copy assignment (shallow copies addresses) diff --git a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H index 6c29a834a7..f3923aab74 100644 --- a/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H +++ b/src/OpenFOAM/containers/PtrLists/UPtrList/UPtrListI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2019 OpenCFD Ltd. + Copyright (C) 2018-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -70,6 +70,13 @@ inline Foam::UPtrList::UPtrList(UPtrList& list, bool reuse) {} +template +inline Foam::UPtrList::UPtrList(const UList& list) +: + ptrs_(list) +{} + + template inline Foam::UPtrList::UPtrList(UList& list) : @@ -172,13 +179,6 @@ inline void Foam::UPtrList::append(T* ptr) } -template -inline const T* Foam::UPtrList::set(const label i) const -{ - return ptrs_[i]; -} - - template inline T* Foam::UPtrList::set(const label i, T* ptr) {