diff --git a/applications/test/List2/Make/files b/applications/test/List2/Make/files index 49c6d304c8..dee86f578b 100644 --- a/applications/test/List2/Make/files +++ b/applications/test/List2/Make/files @@ -1,3 +1,3 @@ -Test-List2.C +Test-List2.cxx EXE = $(FOAM_USER_APPBIN)/Test-List2 diff --git a/applications/test/List2/Test-List2.C b/applications/test/List2/Test-List2.cxx similarity index 84% rename from applications/test/List2/Test-List2.C rename to applications/test/List2/Test-List2.cxx index b054617844..e69f72ab20 100644 --- a/applications/test/List2/Test-List2.C +++ b/applications/test/List2/Test-List2.cxx @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,6 +35,7 @@ Description #include "FixedList.H" #include "labelList.H" #include "vectorList.H" +#include "SubList.H" #include "ListOps.H" #include "IFstream.H" #include "OFstream.H" @@ -200,6 +201,7 @@ int main(int argc, char *argv[]) argList::addBoolOption("order"); argList::addBoolOption("labelList"); argList::addBoolOption("vectorList"); + argList::addBoolOption("ulist"); argList args(argc, argv); @@ -261,6 +263,37 @@ int main(int argc, char *argv[]) } + if (args.found("ulist")) + { + using span_type = stdFoam::span; + using ulist_type = UList; + + ulist_type view1, view2; + span_type span1, span2; + + List list(10, vector::one); + + Info<< "List: " << Foam::name(list.data()) << nl; + Info<< "view: " << Foam::name(view1.data()) << nl; + Info<< "span: " << Foam::name(span1.data()) << nl; + + view1 = list.slice(4); + span1 = span_type(list.begin(4), list.size()-4); + Info<< "view [4]:" << Foam::name(view1.data()) << nl; + Info<< "span [4]:" << Foam::name(span1.data()) << nl; + + view2 = std::move(view1); + span2 = std::move(span1); + Info<< "view old:" << Foam::name(view1.data()) << nl; + Info<< "span old:" << Foam::name(span1.data()) << nl; + Info<< "view [4]:" << Foam::name(view2.data()) << nl; + Info<< "span [4]:" << Foam::name(span2.data()) << nl; + + view1 = list.slice(7); + Info<< "view [7]:" << Foam::name(view1.data()) << nl; + } + + Info<< nl << "Done" << nl << endl; return 0; } diff --git a/src/OpenFOAM/containers/Buffers/CircularBuffer.H b/src/OpenFOAM/containers/Buffers/CircularBuffer.H index 47de665f71..7b3586c2a7 100644 --- a/src/OpenFOAM/containers/Buffers/CircularBuffer.H +++ b/src/OpenFOAM/containers/Buffers/CircularBuffer.H @@ -369,7 +369,7 @@ public: inline void operator=(const T& val); //- Assignment of all entries to zero - inline void operator=(const Foam::zero); + inline void operator=(Foam::zero); //- Deep copy values from a list of the addressed elements inline void operator=(const UList& rhs); diff --git a/src/OpenFOAM/containers/Buffers/CircularBufferI.H b/src/OpenFOAM/containers/Buffers/CircularBufferI.H index 45a1a40d1c..dadbf0ddb6 100644 --- a/src/OpenFOAM/containers/Buffers/CircularBufferI.H +++ b/src/OpenFOAM/containers/Buffers/CircularBufferI.H @@ -567,7 +567,7 @@ inline void Foam::CircularBuffer::operator=(const T& val) template -inline void Foam::CircularBuffer::operator=(const Foam::zero) +inline void Foam::CircularBuffer::operator=(Foam::zero) { this->array_one() = Foam::zero{}; this->array_two() = Foam::zero{}; diff --git a/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.H b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.H index 99873e3b80..b270f20070 100644 --- a/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.H +++ b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.H @@ -187,7 +187,7 @@ public: //- initializing all elements to zero inline CompactListList ( - const label mRows, const label nVals, const Foam::zero + const label mRows, const label nVals, Foam::zero ); //- Construct from number of rows, number of values @@ -422,7 +422,7 @@ public: inline void operator=(const T& val); //- Assignment of all entries to zero - inline void operator=(const Foam::zero); + inline void operator=(Foam::zero); // Row-based access diff --git a/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H index 41c0ed19e9..cc3792c8d4 100644 --- a/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H +++ b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H @@ -100,7 +100,7 @@ inline Foam::CompactListList::CompactListList ( const label mRows, const label nVals, - const Foam::zero + Foam::zero ) : offsets_(mRows+1, Foam::zero{}), @@ -468,7 +468,7 @@ inline void Foam::CompactListList::operator=(const T& val) template -inline void Foam::CompactListList::operator=(const Foam::zero) +inline void Foam::CompactListList::operator=(Foam::zero) { values_ = Foam::zero{}; } diff --git a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H index cb28159c48..6239afd297 100644 --- a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H +++ b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2023 OpenCFD Ltd. + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -101,14 +101,11 @@ public: // Constructors - //- Default construct with default table capacity - HashPtrTable() = default; + //- Default construct: empty without allocation (capacity=0) + constexpr HashPtrTable() noexcept = default; - //- Construct with zero table capacity - explicit HashPtrTable(const Foam::zero) noexcept - : - parent_type(Foam::zero{}) - {} + //- Construct empty without allocation (capacity=0) + explicit constexpr HashPtrTable(Foam::zero) noexcept : this_type() {} //- Construct given initial table capacity explicit HashPtrTable(const label initialCapacity) diff --git a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H index 45bb13f85b..412a3caa59 100644 --- a/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H +++ b/src/OpenFOAM/containers/HashTables/HashSet/HashSet.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2016-2023 OpenCFD Ltd. + Copyright (C) 2016-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -125,13 +125,10 @@ public: // Constructors //- Default construct: empty without allocation (capacity=0) - HashSet() noexcept = default; + constexpr HashSet() noexcept = default; //- Construct empty without allocation (capacity=0) - explicit HashSet(const Foam::zero) noexcept - : - parent_type(Foam::zero{}) - {} + explicit constexpr HashSet(Foam::zero) noexcept : this_type() {} //- Construct empty with initial table capacity explicit HashSet(const label initialCapacity) diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C index 681abd1ea2..e74d5e15fb 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2024 OpenCFD Ltd. + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,7 +37,7 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template -Foam::HashTable::HashTable() noexcept +constexpr Foam::HashTable::HashTable() noexcept : HashTableCore(), size_(0), @@ -46,13 +46,6 @@ Foam::HashTable::HashTable() noexcept {} -template -Foam::HashTable::HashTable(const Foam::zero) noexcept -: - HashTable() -{} - - template Foam::HashTable::HashTable(const label initialCapacity) : diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H index 5e4c659380..03df38925e 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.H @@ -235,10 +235,10 @@ public: // Constructors //- Default construct: empty without allocation (capacity=0) - HashTable() noexcept; + constexpr HashTable() noexcept; //- Construct empty without allocation (capacity=0) - explicit HashTable(const Foam::zero) noexcept; + explicit constexpr HashTable(Foam::zero) noexcept : HashTable() {} //- Construct empty with initial table capacity explicit HashTable(const label initialCapacity); diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableCore.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableCore.H index b9af32082a..b439991539 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableCore.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableCore.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,7 +31,6 @@ Description Template invariant parts of hash table implementation. SourceFiles - HashTableCoreI.H HashTableCore.C \*---------------------------------------------------------------------------*/ @@ -66,7 +65,7 @@ struct HashTableCore ClassName("HashTable"); //- Default construct - HashTableCore() noexcept = default; + constexpr HashTableCore() noexcept = default; static_assert ( @@ -75,7 +74,9 @@ struct HashTableCore ); - //- Factory class for creating a begin/end pair for any const iterator. + //- Factory class for creating a begin/end pair for any const iterator + //- type, normally associated with a HashTable. + // Uses begin iterator and size for bookkeeping. template class const_iterator_pair { @@ -85,19 +86,27 @@ struct HashTableCore public: //- Default construct an empty pair - inline const_iterator_pair(); + const_iterator_pair() + : + size_(0), + iter_() + {} //- Construct begin/end pair for table - inline const_iterator_pair(const TableType& tbl); + const_iterator_pair(const TableType& tbl) + : + size_(tbl.size()), + iter_(tbl.begin()) + {} bool empty() const noexcept { return !size_; } label size() const noexcept { return size_; } - inline IteratorType begin() const; - inline IteratorType cbegin() const; + IteratorType begin() const noexcept { return iter_; } + IteratorType cbegin() const noexcept { return iter_; } - inline IteratorType end() const; - inline IteratorType cend() const; + IteratorType end() const { return IteratorType(); } + IteratorType cend() const { return IteratorType(); } }; }; @@ -108,10 +117,6 @@ struct HashTableCore // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#include "HashTableCoreI.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTableCoreI.H b/src/OpenFOAM/containers/HashTables/HashTable/HashTableCoreI.H index e4c39787c7..7cec1b4541 100644 --- a/src/OpenFOAM/containers/HashTables/HashTable/HashTableCoreI.H +++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTableCoreI.H @@ -1,95 +1 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | www.openfoam.com - \\/ M anipulation | -------------------------------------------------------------------------------- - Copyright (C) 2017-2020 OpenCFD Ltd. -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -// * * * * * * * * * * * * * const iterator pair * * * * * * * * * * * * * * // - -template -inline Foam::HashTableCore::const_iterator_pair -::const_iterator_pair() -: - size_(0), - iter_() -{} - - -template -inline Foam::HashTableCore::const_iterator_pair -::const_iterator_pair -( - const TableType& tbl -) -: - size_(tbl.size()), - iter_(tbl.begin()) -{} - - -template -inline IteratorType Foam::HashTableCore::const_iterator_pair -< - IteratorType, - TableType ->::begin() const -{ - return iter_; -} - - -template -inline IteratorType Foam::HashTableCore::const_iterator_pair -< - IteratorType, - TableType ->::cbegin() const -{ - return iter_; -} - - -template -inline IteratorType Foam::HashTableCore::const_iterator_pair -< - IteratorType, - TableType ->::end() const -{ - return IteratorType(); -} - - -template -inline IteratorType Foam::HashTableCore::const_iterator_pair -< - IteratorType, - TableType ->::cend() const -{ - return IteratorType(); -} - - -// ************************************************************************* // +#warning File removed - left for old dependency check only diff --git a/src/OpenFOAM/containers/HashTables/Map/Map.H b/src/OpenFOAM/containers/HashTables/Map/Map.H index a2b91f1746..c4095399fa 100644 --- a/src/OpenFOAM/containers/HashTables/Map/Map.H +++ b/src/OpenFOAM/containers/HashTables/Map/Map.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2024 OpenCFD Ltd. + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -74,13 +74,10 @@ public: // Constructors //- Default construct: empty without allocation (capacity=0) - Map() noexcept = default; + constexpr Map() noexcept = default; //- Construct empty without allocation (capacity=0) - explicit Map(const Foam::zero) noexcept - : - parent_type(Foam::zero{}) - {} + explicit constexpr Map(Foam::zero) noexcept : this_type() {} //- Construct empty with given initial table capacity explicit Map(const label initialCapacity) diff --git a/src/OpenFOAM/containers/HashTables/PtrMap/PtrMap.H b/src/OpenFOAM/containers/HashTables/PtrMap/PtrMap.H index 50360060d9..f46aff29c8 100644 --- a/src/OpenFOAM/containers/HashTables/PtrMap/PtrMap.H +++ b/src/OpenFOAM/containers/HashTables/PtrMap/PtrMap.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2023 OpenCFD Ltd. + Copyright (C) 2017-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -66,13 +66,10 @@ public: // Constructors //- Default construct: empty without allocation (capacity=0) - PtrMap() noexcept = default; + constexpr PtrMap() noexcept = default; //- Construct empty without allocation (capacity=0) - explicit PtrMap(const Foam::zero) noexcept - : - parent_type(Foam::zero{}) - {} + explicit constexpr PtrMap(Foam::zero) noexcept : this_type() {} //- Construct empty with given initial table capacity explicit PtrMap(const label initialCapacity) diff --git a/src/OpenFOAM/containers/IndirectLists/IndirectList/IndirectList.H b/src/OpenFOAM/containers/IndirectLists/IndirectList/IndirectList.H index 38260ce2f6..4a00d9a335 100644 --- a/src/OpenFOAM/containers/IndirectLists/IndirectList/IndirectList.H +++ b/src/OpenFOAM/containers/IndirectLists/IndirectList/IndirectList.H @@ -130,7 +130,7 @@ public: inline IndirectList(const UList& values, labelList&& addr); //- Zero-sized addressing, shallow copy values reference - inline IndirectList(const UList& values, const Foam::zero); + inline IndirectList(const UList& values, Foam::zero); //- Copy construct addressing, shallow copy values reference inline IndirectList(const IndirectList& list); diff --git a/src/OpenFOAM/containers/IndirectLists/IndirectList/IndirectListI.H b/src/OpenFOAM/containers/IndirectLists/IndirectList/IndirectListI.H index eae0ddb4b0..d179d1c0bc 100644 --- a/src/OpenFOAM/containers/IndirectLists/IndirectList/IndirectListI.H +++ b/src/OpenFOAM/containers/IndirectLists/IndirectList/IndirectListI.H @@ -64,7 +64,7 @@ template inline Foam::IndirectList::IndirectList ( const UList& values, - const Foam::zero + Foam::zero ) : IndirectListAddressing(labelList()), // zero-size addressing diff --git a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H index 03caf4f4fa..03ea65004c 100644 --- a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H +++ b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBase.H @@ -215,7 +215,7 @@ public: inline void operator=(const T& val); //- Assignment of all entries to zero - inline void operator=(const Foam::zero); + inline void operator=(Foam::zero); //- Deep copy values from a list of the addressed elements // Fatal if list sizes are not identical diff --git a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBaseI.H b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBaseI.H index abb311cfd9..b91aea2168 100644 --- a/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBaseI.H +++ b/src/OpenFOAM/containers/IndirectLists/IndirectListBase/IndirectListBaseI.H @@ -223,7 +223,7 @@ inline void Foam::IndirectListBase::operator=(const T& val) template -inline void Foam::IndirectListBase::operator=(const Foam::zero) +inline void Foam::IndirectListBase::operator=(Foam::zero) { // Or std::fill(this->begin(), this->end(), Zero); for (const label idx : addr_) diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H index c85d22ae2c..1ab95b9f1c 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H @@ -124,7 +124,7 @@ public: inline DynamicList(const label len, const T& val); //- Construct with given size initializing all elements to zero - inline DynamicList(const label len, const Foam::zero); + inline DynamicList(const label len, Foam::zero); //- Copy construct. inline DynamicList(const DynamicList& lst); @@ -349,7 +349,7 @@ public: inline void operator=(const T& val); //- Assignment of all entries to zero - inline void operator=(const Foam::zero); + inline void operator=(Foam::zero); //- Assignment to UList inline void operator=(const UList& lst); diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H index 178544aa2a..8ad549eecd 100644 --- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H +++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H @@ -168,7 +168,7 @@ template inline Foam::DynamicList::DynamicList ( const label len, - const Foam::zero + Foam::zero ) : List(len, Foam::zero{}), @@ -831,7 +831,7 @@ inline void Foam::DynamicList::operator= template inline void Foam::DynamicList::operator= ( - const Foam::zero + Foam::zero ) { UList::operator=(Foam::zero{}); diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index 8a6abaa91f..e5db262820 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -157,7 +157,7 @@ public: inline explicit FixedList(const T& val); //- Construct and initialize all entries to zero - inline explicit FixedList(const Foam::zero); + inline explicit FixedList(Foam::zero); //- Copy construct inline FixedList(const FixedList& list); @@ -330,7 +330,7 @@ public: inline void fill(const T& val); //- Assign all entries to zero - inline void fill(const Foam::zero); + inline void fill(Foam::zero); //- Move element to the first position. void moveFirst(const label i); @@ -367,7 +367,7 @@ public: inline void operator=(const T& val); //- Assign all entries to zero. fill() - inline void operator=(const Foam::zero); + inline void operator=(Foam::zero); //- Copy assignment inline void operator=(const FixedList& list); diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H index 61fe38572f..1948846e10 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H @@ -38,7 +38,7 @@ inline Foam::FixedList::FixedList(const T& val) template -inline Foam::FixedList::FixedList(const Foam::zero) +inline Foam::FixedList::FixedList(Foam::zero) { this->fill(Foam::zero{}); } @@ -354,7 +354,7 @@ inline void Foam::FixedList::fill(const T& val) template -inline void Foam::FixedList::fill(const Foam::zero) +inline void Foam::FixedList::fill(Foam::zero) { // Usually small enough that parallel execution is pointless... // Cannot use std::fill (ambiguous conversions for bool, char, etc) @@ -441,7 +441,7 @@ inline void Foam::FixedList::operator=(const T& val) template -inline void Foam::FixedList::operator=(const Foam::zero) +inline void Foam::FixedList::operator=(Foam::zero) { this->fill(Foam::zero{}); } diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index 6249cedb7b..61e23d1e73 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -123,7 +123,7 @@ Foam::List::List(const label len, const T& val) template -Foam::List::List(const label len, const Foam::zero) +Foam::List::List(const label len, Foam::zero) : UList(nullptr, len) { @@ -143,7 +143,7 @@ Foam::List::List(const label len, const Foam::zero) template -Foam::List::List(const Foam::one, const T& val) +Foam::List::List(Foam::one, const T& val) : UList(new T[1], 1) { @@ -152,7 +152,7 @@ Foam::List::List(const Foam::one, const T& val) template -Foam::List::List(const Foam::one, T&& val) +Foam::List::List(Foam::one, T&& val) : UList(new T[1], 1) { @@ -161,7 +161,7 @@ Foam::List::List(const Foam::one, T&& val) template -Foam::List::List(const Foam::one, const Foam::zero) +Foam::List::List(Foam::one, Foam::zero) : UList(new T[1], 1) { diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index d333d8001f..8f2d96a99f 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -148,16 +148,16 @@ public: List(const label len, const T& val); //- Construct with given size initializing all elements to zero - List(const label len, const Foam::zero); + List(const label len, Foam::zero); //- Construct with length=1, copying the value as the only content - List(const Foam::one, const T& val); + List(Foam::one, const T& val); //- Construct with length=1, moving the value as the only content - List(const Foam::one, T&& val); + List(Foam::one, T&& val); //- Construct with length=1, initializing content to zero - List(const Foam::one, const Foam::zero); + List(Foam::one, Foam::zero); //- Copy construct from list List(const List& list); @@ -316,7 +316,7 @@ public: inline void operator=(const T& val); //- Assignment of all entries to zero - inline void operator=(const Foam::zero); + inline void operator=(Foam::zero); //- Move assignment. Takes constant time void operator=(List&& list); diff --git a/src/OpenFOAM/containers/Lists/List/ListI.H b/src/OpenFOAM/containers/Lists/List/ListI.H index 5bac2f0ee4..bdb510f837 100644 --- a/src/OpenFOAM/containers/Lists/List/ListI.H +++ b/src/OpenFOAM/containers/Lists/List/ListI.H @@ -320,7 +320,7 @@ inline void Foam::List::operator=(const T& val) template -inline void Foam::List::operator=(const Foam::zero) +inline void Foam::List::operator=(Foam::zero) { UList::operator=(Foam::zero{}); } diff --git a/src/OpenFOAM/containers/Lists/List/SubList.H b/src/OpenFOAM/containers/Lists/List/SubList.H index 42f2a1dcd6..2cd0e10c18 100644 --- a/src/OpenFOAM/containers/Lists/List/SubList.H +++ b/src/OpenFOAM/containers/Lists/List/SubList.H @@ -28,11 +28,7 @@ Class Foam::SubList Description - A List obtained as a section of another List. - - Since the SubList is itself unallocated, no storage is allocated or - de-allocated during its use. To achieve this behaviour, SubList is - derived from UList rather than List. + A non-owning sub-view of a List (allocated or unallocated storage). SourceFiles SubListI.H @@ -178,10 +174,12 @@ public: //- Allow cast to a const List\& inline operator const Foam::List&() const; - //- Copy assign entries from given sub-list. Sizes must match! + //- Copy assign entries (deep copy) from given sub-list. + //- Sizes must match! inline void operator=(const SubList& list); - //- Copy assign entries from given list. Sizes must match! + //- Copy assign entries (deep copy) from given list. + //- Sizes must match! inline void operator=(const UList& list); //- Copy assign entries from given indirect list. Sizes must match! @@ -192,7 +190,7 @@ public: inline void operator=(const T& val); //- Assign all entries to zero - inline void operator=(const Foam::zero); + inline void operator=(Foam::zero); }; @@ -206,6 +204,13 @@ public: // * * * * * * * * * * * * * * * Implementations * * * * * * * * * * * * * * // +template +Foam::UList::UList(SubList&& list) noexcept +: + UList(list.data(), list.size()) +{} + + template Foam::SubList Foam::UList::slice(const label pos, label len) diff --git a/src/OpenFOAM/containers/Lists/List/SubListI.H b/src/OpenFOAM/containers/Lists/List/SubListI.H index f18c31646b..1bec82958e 100644 --- a/src/OpenFOAM/containers/Lists/List/SubListI.H +++ b/src/OpenFOAM/containers/Lists/List/SubListI.H @@ -251,7 +251,7 @@ inline void Foam::SubList::operator=(const T& val) template -inline void Foam::SubList::operator=(const Foam::zero) +inline void Foam::SubList::operator=(Foam::zero) { UList::operator=(Foam::zero{}); } diff --git a/src/OpenFOAM/containers/Lists/List/UList.C b/src/OpenFOAM/containers/Lists/List/UList.C index df54e1770e..4fcc176e0a 100644 --- a/src/OpenFOAM/containers/Lists/List/UList.C +++ b/src/OpenFOAM/containers/Lists/List/UList.C @@ -155,7 +155,7 @@ void Foam::UList::deepCopy(const IndirectListBase& list) // This is non-inlined to allow template specializations template -void Foam::UList::operator=(const Foam::zero) +void Foam::UList::operator=(Foam::zero) { this->fill_uniform(Foam::zero{}); } diff --git a/src/OpenFOAM/containers/Lists/List/UList.H b/src/OpenFOAM/containers/Lists/List/UList.H index 639a60cf4e..e027fb35fb 100644 --- a/src/OpenFOAM/containers/Lists/List/UList.H +++ b/src/OpenFOAM/containers/Lists/List/UList.H @@ -124,15 +124,8 @@ protected: //- Assign all entries to zero // Caution: method name subject to change - inline void fill_uniform(const Foam::zero); + inline void fill_uniform(Foam::zero); - //- No copy assignment (default: shallow copy) - // - // Assignment may need to be shallow (copy pointer) - // or deep (copy elements) depending on context or type of list. - // Disallow default assignment and provide separate 'shallowCopy' and - // 'deepCopy' member functions. - UList& operator=(const UList&) = delete; public: @@ -228,8 +221,22 @@ public: // Generated Methods - //- Copy construct - UList(const UList&) = default; + //- Copy construct, shallow copy + UList(const UList&) noexcept = default; + + //- Move construct, shallow copy + UList(UList&&) noexcept = default; + + //- No copy assignment (default: shallow copy) + // Assignment may need to be shallow (copy pointer) + // or deep (copy elements) depending on context or type of list. + // Disallow default assignment and provide separate 'shallowCopy' and + // 'deepCopy' member functions. + UList& operator=(const UList&) = delete; + + //- Move assignment, shallow copy. + // No ambiguity between shallow or deep copying in this form. + UList& operator=(UList&&) noexcept = default; // Constructors @@ -238,7 +245,10 @@ public: inline constexpr UList() noexcept; //- Construct from components - inline UList(T* __restrict__ v, const label len) noexcept; + inline UList(T* __restrict__ ptr, const label len) noexcept; + + //- Move construct from a SubList, shallow copy + UList(SubList&&) noexcept; // Member Functions @@ -421,7 +431,7 @@ public: inline void operator=(const T& val); //- Assignment of all entries to zero - void operator=(const Foam::zero); + void operator=(Foam::zero); // Random access iterator (non-const) @@ -658,7 +668,7 @@ void UList::writeEntry(Ostream& os) const; //- Character list assign zero - avoids Foam::zero casting ambiguities template<> -void UList::operator=(const Foam::zero); +void UList::operator=(Foam::zero); // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/Lists/List/UListI.H b/src/OpenFOAM/containers/Lists/List/UListI.H index d2f88ffb6f..de385d6116 100644 --- a/src/OpenFOAM/containers/Lists/List/UListI.H +++ b/src/OpenFOAM/containers/Lists/List/UListI.H @@ -40,10 +40,10 @@ inline constexpr Foam::UList::UList() noexcept template -inline Foam::UList::UList(T* __restrict__ v, const label len) noexcept +inline Foam::UList::UList(T* __restrict__ ptr, const label len) noexcept : size_(len), - v_(v) + v_(ptr) {} @@ -63,7 +63,7 @@ inline void Foam::UList::fill_uniform(const T& val) template -inline void Foam::UList::fill_uniform(const Foam::zero) +inline void Foam::UList::fill_uniform(Foam::zero) { // Note: ambiguous conversions for char can still cause compilation // issues. diff --git a/src/OpenFOAM/containers/Lists/SortableList/SortableList.C b/src/OpenFOAM/containers/Lists/SortableList/SortableList.C index f4fe772ba0..8f59414790 100644 --- a/src/OpenFOAM/containers/Lists/SortableList/SortableList.C +++ b/src/OpenFOAM/containers/Lists/SortableList/SortableList.C @@ -36,7 +36,7 @@ inline Foam::SortableList::SortableList(const label size) template -inline Foam::SortableList::SortableList(const label size, const Foam::zero) +inline Foam::SortableList::SortableList(const label size, Foam::zero) : List(size, Foam::zero{}) {} diff --git a/src/OpenFOAM/containers/Lists/SortableList/SortableList.H b/src/OpenFOAM/containers/Lists/SortableList/SortableList.H index a10c8934d8..dde952fc8e 100644 --- a/src/OpenFOAM/containers/Lists/SortableList/SortableList.H +++ b/src/OpenFOAM/containers/Lists/SortableList/SortableList.H @@ -81,7 +81,7 @@ public: //- Construct zero-initialized with given size, sort later. // The indices remain empty until the list is sorted - inline SortableList(const label size, const Foam::zero); + inline SortableList(const label size, Foam::zero); //- Construct given size and initial value, sorting later. // The indices remain empty until the list is sorted