From 5ee8f19bdd0ba88895c29ac36834ea638e7ccc30 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Fri, 25 Apr 2025 10:34:42 +0200
Subject: [PATCH 1/2] ENH: refine handling of DynamicList/DynamicField resizing

- previously had special resizing treatment for the corner case when
  the addressable size and the new capacity are identical. However,
  that particular approach (to minimize copying) meant that the exact
  deallocation size would likely be incorrect.
  Having the correct deallocation size becomes more important with
  alternative allocators.

  Introduce resize_copy() protected function to limit the number
  of elements copied during the resize.

ENH: provide DynamicList/DynamicField constructor with sizing

- allows fine-grained creation of a DynamicList/DynamicField with a
  given size/capacity without an initial value.

COMP: typo in code for DynamicList::push_back() with IndirectList
---
 applications/test/DynamicList/Make/files      |  2 +-
 ...est-DynamicList.C => Test-DynamicList.cxx} |  0
 applications/test/DynamicList2/Make/files     |  2 +-
 ...t-DynamicList2.C => Test-DynamicList2.cxx} | 22 ++++++-
 applications/test/List3/Make/files            |  2 +-
 .../List3/{Test-List3.C => Test-List3.cxx}    |  0
 applications/test/PackedList1/Make/files      |  2 +-
 ...est-PackedList1.C => Test-PackedList1.cxx} |  0
 applications/test/PackedList2/Make/files      |  2 +-
 ...est-PackedList2.C => Test-PackedList2.cxx} |  0
 applications/test/UIndirectList/Make/files    |  2 +-
 ...UIndirectList.C => Test-UIndirectList.cxx} |  0
 applications/test/bitSet2/Make/files          |  2 +-
 .../{Test-bitSet2.C => Test-bitSet2.cxx}      |  2 +-
 .../containers/Bits/PackedList/PackedList.H   |  5 +-
 .../containers/Bits/PackedList/PackedListI.H  |  2 +-
 .../Lists/DynamicList/DynamicList.H           | 42 +++++++-----
 .../Lists/DynamicList/DynamicListI.H          | 57 ++++++----------
 src/OpenFOAM/containers/Lists/List/List.C     | 57 +++++++++-------
 src/OpenFOAM/containers/Lists/List/List.H     | 14 ++--
 src/OpenFOAM/containers/Lists/List/ListI.H    | 14 ++--
 .../PtrLists/PtrDynList/PtrDynList.H          | 13 +++-
 .../PtrLists/PtrDynList/PtrDynListI.H         | 16 ++++-
 .../containers/PtrLists/PtrList/PtrList.H     |  2 +-
 .../fields/Fields/DynamicField/DynamicField.H | 53 ++++++++-------
 .../Fields/DynamicField/DynamicFieldI.H       | 66 +++++++++----------
 26 files changed, 216 insertions(+), 163 deletions(-)
 rename applications/test/DynamicList/{Test-DynamicList.C => Test-DynamicList.cxx} (100%)
 rename applications/test/DynamicList2/{Test-DynamicList2.C => Test-DynamicList2.cxx} (87%)
 rename applications/test/List3/{Test-List3.C => Test-List3.cxx} (100%)
 rename applications/test/PackedList1/{Test-PackedList1.C => Test-PackedList1.cxx} (100%)
 rename applications/test/PackedList2/{Test-PackedList2.C => Test-PackedList2.cxx} (100%)
 rename applications/test/UIndirectList/{Test-UIndirectList.C => Test-UIndirectList.cxx} (100%)
 rename applications/test/bitSet2/{Test-bitSet2.C => Test-bitSet2.cxx} (99%)

diff --git a/applications/test/DynamicList/Make/files b/applications/test/DynamicList/Make/files
index b496842582c..76d78735b0c 100644
--- a/applications/test/DynamicList/Make/files
+++ b/applications/test/DynamicList/Make/files
@@ -1,3 +1,3 @@
-Test-DynamicList.C
+Test-DynamicList.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-DynamicList
diff --git a/applications/test/DynamicList/Test-DynamicList.C b/applications/test/DynamicList/Test-DynamicList.cxx
similarity index 100%
rename from applications/test/DynamicList/Test-DynamicList.C
rename to applications/test/DynamicList/Test-DynamicList.cxx
diff --git a/applications/test/DynamicList2/Make/files b/applications/test/DynamicList2/Make/files
index 78b8198c6a0..ceb29c77127 100644
--- a/applications/test/DynamicList2/Make/files
+++ b/applications/test/DynamicList2/Make/files
@@ -1,3 +1,3 @@
-Test-DynamicList2.C
+Test-DynamicList2.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-DynamicList2
diff --git a/applications/test/DynamicList2/Test-DynamicList2.C b/applications/test/DynamicList2/Test-DynamicList2.cxx
similarity index 87%
rename from applications/test/DynamicList2/Test-DynamicList2.C
rename to applications/test/DynamicList2/Test-DynamicList2.cxx
index e75e0d29862..ef47d267834 100644
--- a/applications/test/DynamicList2/Test-DynamicList2.C
+++ b/applications/test/DynamicList2/Test-DynamicList2.cxx
@@ -52,7 +52,8 @@ void printInfo
     if (showSize)
     {
         Info<< " size=\"" << list.size()
-            << "\" capacity=\"" << list.capacity() << "\"";
+            << "\" capacity=\"" << list.capacity() << "\""
+            << "\" min=\"" << SizeMin << "\"" ;
         if (list.cdata())
         {
             Info<< " ptr=\"" << name(list.cdata()) << "\"";
@@ -79,7 +80,8 @@ void printInfo
     if (showSize)
     {
         Info<< " size=\"" << list.size()
-            << "\" capacity=\"" << list.capacity() << "\"";
+            << "\" capacity=\"" << list.capacity() << "\""
+            << "\" min=\"" << SizeMin << "\"" ;
         if (list.cdata())
         {
             Info<< " ptr=\"" << name(list.cdata()) << "\"";
@@ -168,6 +170,22 @@ int main(int argc, char *argv[])
         printInfo("", list2);
     }
 
+    {
+        DynamicList<float, 32> list1(std::pair<label,label>(16,0));
+        list1 = -1;
+
+        Info<< "construct with specified size/capacity" << nl;
+        printInfo("", list1);
+    }
+
+    {
+        DynamicList<float, 32> list1(std::pair<label,label>(8,16));
+        list1 = -1;
+
+        Info<< "construct with specified size/capacity" << nl;
+        printInfo("", list1);
+    }
+
     Info<< "\nEnd\n";
 
     return 0;
diff --git a/applications/test/List3/Make/files b/applications/test/List3/Make/files
index 640cc113d78..93c443e14e2 100644
--- a/applications/test/List3/Make/files
+++ b/applications/test/List3/Make/files
@@ -1,3 +1,3 @@
-Test-List3.C
+Test-List3.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-List3
diff --git a/applications/test/List3/Test-List3.C b/applications/test/List3/Test-List3.cxx
similarity index 100%
rename from applications/test/List3/Test-List3.C
rename to applications/test/List3/Test-List3.cxx
diff --git a/applications/test/PackedList1/Make/files b/applications/test/PackedList1/Make/files
index 76843f21f9f..0b2b68d6ff5 100644
--- a/applications/test/PackedList1/Make/files
+++ b/applications/test/PackedList1/Make/files
@@ -1,3 +1,3 @@
-Test-PackedList1.C
+Test-PackedList1.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-PackedList1
diff --git a/applications/test/PackedList1/Test-PackedList1.C b/applications/test/PackedList1/Test-PackedList1.cxx
similarity index 100%
rename from applications/test/PackedList1/Test-PackedList1.C
rename to applications/test/PackedList1/Test-PackedList1.cxx
diff --git a/applications/test/PackedList2/Make/files b/applications/test/PackedList2/Make/files
index ce31f2fa8dd..7c20add1a55 100644
--- a/applications/test/PackedList2/Make/files
+++ b/applications/test/PackedList2/Make/files
@@ -1,3 +1,3 @@
-Test-PackedList2.C
+Test-PackedList2.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-PackedList2
diff --git a/applications/test/PackedList2/Test-PackedList2.C b/applications/test/PackedList2/Test-PackedList2.cxx
similarity index 100%
rename from applications/test/PackedList2/Test-PackedList2.C
rename to applications/test/PackedList2/Test-PackedList2.cxx
diff --git a/applications/test/UIndirectList/Make/files b/applications/test/UIndirectList/Make/files
index 8f705219896..9be6c131786 100644
--- a/applications/test/UIndirectList/Make/files
+++ b/applications/test/UIndirectList/Make/files
@@ -1,3 +1,3 @@
-Test-UIndirectList.C
+Test-UIndirectList.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-UIndirectList
diff --git a/applications/test/UIndirectList/Test-UIndirectList.C b/applications/test/UIndirectList/Test-UIndirectList.cxx
similarity index 100%
rename from applications/test/UIndirectList/Test-UIndirectList.C
rename to applications/test/UIndirectList/Test-UIndirectList.cxx
diff --git a/applications/test/bitSet2/Make/files b/applications/test/bitSet2/Make/files
index ff546fa179b..e3ceca9e230 100644
--- a/applications/test/bitSet2/Make/files
+++ b/applications/test/bitSet2/Make/files
@@ -1,3 +1,3 @@
-Test-bitSet2.C
+Test-bitSet2.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-bitSet2
diff --git a/applications/test/bitSet2/Test-bitSet2.C b/applications/test/bitSet2/Test-bitSet2.cxx
similarity index 99%
rename from applications/test/bitSet2/Test-bitSet2.C
rename to applications/test/bitSet2/Test-bitSet2.cxx
index fb9bc746a18..8f9f5d487e2 100644
--- a/applications/test/bitSet2/Test-bitSet2.C
+++ b/applications/test/bitSet2/Test-bitSet2.cxx
@@ -499,7 +499,7 @@ int main(int argc, char *argv[])
         Info<<"bitSet ";
         report(list4);
 
-        list4.shrink();
+        list4.shrink_to_fit();
         Info<<"shrunk ";
         report(list4);
 
diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedList.H b/src/OpenFOAM/containers/Bits/PackedList/PackedList.H
index 5bdbbceb6a1..aa6c7559623 100644
--- a/src/OpenFOAM/containers/Bits/PackedList/PackedList.H
+++ b/src/OpenFOAM/containers/Bits/PackedList/PackedList.H
@@ -406,7 +406,10 @@ public:
         inline void clearStorage();
 
         //- Shrink the allocated space to what is actually used.
-        inline void shrink();
+        inline void shrink_to_fit();
+
+        //- Alias for shrink_to_fit()
+        void shrink() { this->shrink_to_fit(); }
 
         //- Swap contents with argument
         inline void swap(PackedList<Width>& rhs);
diff --git a/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H b/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H
index 8bdd10ddcc7..a8e7f93dd9f 100644
--- a/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H
+++ b/src/OpenFOAM/containers/Bits/PackedList/PackedListI.H
@@ -597,7 +597,7 @@ inline void Foam::PackedList<Width>::clearStorage()
 
 
 template<unsigned Width>
-inline void Foam::PackedList<Width>::shrink()
+inline void Foam::PackedList<Width>::shrink_to_fit()
 {
     // Any unneeded space allocated?
     const label nblocks = num_blocks(size());
diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H
index 78385c9b5bf..bf8768d9bc1 100644
--- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H
+++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H
@@ -120,6 +120,9 @@ public:
         //- Construct an empty list with given initial capacity
         inline explicit DynamicList(const label initialCapacity);
 
+        //- Construct with given size and capacity
+        inline explicit DynamicList(const std::pair<label,label>& sizing);
+
         //- Construct with given size and value for all elements.
         inline DynamicList(const label len, const T& val);
 
@@ -133,21 +136,21 @@ public:
         template<int AnySizeMin>
         inline DynamicList(const DynamicList<T, AnySizeMin>& lst);
 
-        //- Construct from UList. Size set to UList size.
+        //- Copy construct from UList. Size set to UList size.
         //  Also constructs from DynamicList with different sizing parameters.
         inline explicit DynamicList(const UList<T>& lst);
 
         //- Copy construct subset of list
         inline DynamicList(const UList<T>& list, const labelUList& indices);
 
-        //- Construct from a FixedList
+        //- Copy construct from a FixedList
         template<unsigned N>
         inline explicit DynamicList(const FixedList<T, N>& lst);
 
-        //- Construct from an initializer list. Size set to list size.
+        //- Copy construct from an initializer list. Size set to list size.
         inline explicit DynamicList(std::initializer_list<T> lst);
 
-        //- Construct from IndirectList. Size set to addressing size.
+        //- Copy construct from IndirectList. Size set to addressing size.
         template<class Addr>
         inline explicit DynamicList(const IndirectListBase<T, Addr>& lst);
 
@@ -200,7 +203,7 @@ public:
 
         //- Change the value for the list capacity directly (ADVANCED, UNSAFE)
         //- Does not perform any memory management or resizing.
-        inline void setCapacity_unsafe(const label len) noexcept;
+        void setCapacity_unsafe(const label len) noexcept { capacity_ = len; }
 
         //- Reserve allocation space for at least this size, allocating new
         //- space if required and \em retaining old content.
@@ -238,12 +241,6 @@ public:
         //  Otherwise all entries will be uninitialized.
         inline void resize_nocopy(const label len);
 
-        //- Same as resize()
-        void setSize(const label n) { this->resize(n); }
-
-        //- Same as resize()
-        void setSize(const label n, const T& val) { this->resize(n, val); }
-
         //- Clear the addressed list, i.e. set the size to zero.
         //  Allocated size does not change
         inline void clear() noexcept;
@@ -259,9 +256,6 @@ public:
         //  \note when empty() it will delete any allocated memory.
         inline void shrink_unsafe();
 
-        //- Calls shrink_to_fit() and returns a reference to the DynamicList.
-        inline DynamicList<T, SizeMin>& shrink();
-
 
     // Edit
 
@@ -304,7 +298,7 @@ public:
         template<class Addr>
         inline void push_back(const IndirectListBase<T, Addr>& lst);
 
-        //- Move append list
+        //- Move append another list to the end of this list
         inline void push_back(List<T>&& list);
 
         //- Move append list
@@ -355,10 +349,10 @@ public:
             //- Return non-const access to an element, resizing list if needed
             inline T& operator()(const label i);
 
-            //- Assignment of all addressed entries to the given value
+            //- Assign addressed entries to the given value
             inline void operator=(const T& val);
 
-            //- Assignment of all entries to zero
+            //- Assign addressed entries to zero
             inline void operator=(Foam::zero);
 
             //- Assignment to UList
@@ -418,6 +412,20 @@ public:
 
     // Housekeeping
 
+        //- Alias for resize()
+        void setSize(const label n) { this->resize(n); }
+
+        //- Alias for resize()
+        void setSize(const label n, const T& val) { this->resize(n, val); }
+
+        //- Calls shrink_to_fit() and returns a reference to the DynamicList.
+        //FOAM_DEPRECATED_FOR(2025-04, "shrink_to_fit()")
+        DynamicList<T, SizeMin>& shrink()
+        {
+            this->shrink_to_fit();
+            return *this;
+        }
+
         //- Copy append an element to the end of this list.
         //FOAM_DEPRECATED_FOR(2022-10, "push_back()")
         void append(const T& val) { this->push_back(val); }
diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H
index a3c004cd8ae..17e199242d1 100644
--- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H
+++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H
@@ -42,7 +42,7 @@ inline void Foam::DynamicList<T, SizeMin>::doAssignDynList
     if (capacity_ < len)
     {
         // Needs more space for the copy operation
-        List<T>::setAddressableSize(capacity_);  // Use entire space
+        List<T>::setAddressableSize(capacity_);
         List<T>::resize_nocopy(len);
         capacity_ = List<T>::size();
     }
@@ -68,23 +68,14 @@ inline void Foam::DynamicList<T, SizeMin>::doCapacity
     // Addressable length, possibly truncated by new capacity
     const label currLen = Foam::min(List<T>::size(), newCapacity);
 
-    // Corner case...
-    if (List<T>::size() == newCapacity)
-    {
-        // Adjust addressable size to trigger proper resizing.
-        // Using (old size+1) is safe since it does not affect the 'overlap'
-        // of old and new addressable regions, but incurs fewew copy
-        // operations than extending to use the current capacity would.
-        List<T>::setAddressableSize(currLen+1);
-    }
-
+    List<T>::setAddressableSize(capacity_);
     if (nocopy)
     {
         List<T>::resize_nocopy(newCapacity);
     }
     else
     {
-        List<T>::resize(newCapacity);
+        List<T>::resize_copy(currLen, newCapacity);
     }
 
     capacity_ = List<T>::size();
@@ -153,6 +144,19 @@ inline Foam::DynamicList<T, SizeMin>::DynamicList(const label initialCapacity)
 }
 
 
+template<class T, int SizeMin>
+inline Foam::DynamicList<T, SizeMin>::DynamicList
+(
+    const std::pair<label,label>& sizing
+)
+:
+    List<T>(std::max(sizing.first, sizing.second)),
+    capacity_(List<T>::size())
+{
+    List<T>::setAddressableSize(sizing.first);
+}
+
+
 template<class T, int SizeMin>
 inline Foam::DynamicList<T, SizeMin>::DynamicList
 (
@@ -326,16 +330,6 @@ inline void Foam::DynamicList<T, SizeMin>::setCapacity_nocopy
 }
 
 
-template<class T, int SizeMin>
-inline void Foam::DynamicList<T, SizeMin>::setCapacity_unsafe
-(
-    const label len
-) noexcept
-{
-    capacity_ = len;
-}
-
-
 template<class T, int SizeMin>
 inline void Foam::DynamicList<T, SizeMin>::reserve
 (
@@ -448,8 +442,7 @@ inline void Foam::DynamicList<T, SizeMin>::shrink_to_fit()
     const label currLen = List<T>::size();
     if (currLen < capacity_)
     {
-        // Adjust addressable size to trigger proper resizing
-        List<T>::setAddressableSize(currLen+1);
+        List<T>::setAddressableSize(capacity_);
         List<T>::resize(currLen);
         capacity_ = List<T>::size();
     }
@@ -468,15 +461,6 @@ inline void Foam::DynamicList<T, SizeMin>::shrink_unsafe()
 }
 
 
-template<class T, int SizeMin>
-inline Foam::DynamicList<T, SizeMin>&
-Foam::DynamicList<T, SizeMin>::shrink()
-{
-    this->shrink_to_fit();
-    return *this;
-}
-
-
 template<class T, int SizeMin>
 inline void
 Foam::DynamicList<T, SizeMin>::swap(List<T>& list)
@@ -608,7 +592,7 @@ inline void Foam::DynamicList<T, SizeMin>::push_back
     const UList<T>& list
 )
 {
-    if (this == &list)
+    if (FOAM_UNLIKELY(this == &list))
     {
         FatalErrorInFunction
             << "Attempted push_back to self"
@@ -662,8 +646,7 @@ inline void Foam::DynamicList<T, SizeMin>::push_back
 
     const label idx = this->size();
     const label n = list.size();
-
-    resize(list + n);
+    resize(idx + n);
 
     auto iter = this->begin(idx);
 
@@ -680,7 +663,7 @@ inline void Foam::DynamicList<T, SizeMin>::push_back
     List<T>&& list
 )
 {
-    if (this == &list)
+    if (FOAM_UNLIKELY(this == &list))
     {
         FatalErrorInFunction
             << "Attempted push_back to self"
diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C
index bdf09f58c57..c9707ef29bc 100644
--- a/src/OpenFOAM/containers/Lists/List/List.C
+++ b/src/OpenFOAM/containers/Lists/List/List.C
@@ -31,31 +31,34 @@ License
 #include "PtrList.H"
 #include "contiguous.H"
 
-// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+// * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
 
 template<class T>
-void Foam::List<T>::doResize(const label len)
+void Foam::List<T>::resize_copy(const label count, const label len)
 {
-    if (len == this->size_)
-    {
-        return;
-    }
+    // Only a limited number of internal size checks.
+    // Caller knows what they are doing.
 
-    if (len > 0)
+    if (FOAM_LIKELY(len > 0))
     {
         // With sign-check to avoid spurious -Walloc-size-larger-than
-        const label overlap = Foam::min(this->size_, len);
+        // const label oldLen = this->size_;
+        const label overlap = Foam::min(count, len);
+        // Extra safety, not currently necessary:
+        // const label overlap = Foam::min(Foam::min(count, oldLen), len);
+
+        T* old = this->v_;
 
         if (overlap > 0)
         {
             // Recover overlapping content when resizing
-            T* old = this->v_;
+
             this->size_ = len;
             this->v_ = new T[len];
 
             // Can dispatch with
-            // - std::execution::parallel_unsequenced_policy
-            // - std::execution::unsequenced_policy
+            // - std::execution::par_unseq
+            // - std::execution::unseq
             std::move(old, (old + overlap), this->v_);
 
             delete[] old;
@@ -63,7 +66,8 @@ void Foam::List<T>::doResize(const label len)
         else
         {
             // No overlapping content
-            delete[] this->v_;
+            delete[] old;
+
             this->size_ = len;
             this->v_ = new T[len];
         }
@@ -71,7 +75,7 @@ void Foam::List<T>::doResize(const label len)
     else
     {
         // Or only #ifdef FULLDEBUG
-        if (len < 0)
+        if (FOAM_UNLIKELY(len < 0))
         {
             FatalErrorInFunction
                 << "bad size " << len
@@ -91,14 +95,17 @@ Foam::List<T>::List(const label len)
 :
     UList<T>(nullptr, len)
 {
-    if (len < 0)
+    if (FOAM_UNLIKELY(len < 0))
     {
         FatalErrorInFunction
             << "bad size " << len
             << abort(FatalError);
     }
 
-    doAlloc();
+    if (len > 0)
+    {
+        doAlloc();
+    }
 }
 
 
@@ -107,14 +114,14 @@ Foam::List<T>::List(const label len, const T& val)
 :
     UList<T>(nullptr, len)
 {
-    if (len < 0)
+    if (FOAM_UNLIKELY(len < 0))
     {
         FatalErrorInFunction
             << "bad size " << len
             << abort(FatalError);
     }
 
-    if (len)
+    if (len > 0)
     {
         doAlloc();
         UList<T>::operator=(val);
@@ -127,14 +134,14 @@ Foam::List<T>::List(const label len, Foam::zero)
 :
     UList<T>(nullptr, len)
 {
-    if (len < 0)
+    if (FOAM_UNLIKELY(len < 0))
     {
         FatalErrorInFunction
             << "bad size " << len
             << abort(FatalError);
     }
 
-    if (len)
+    if (len > 0)
     {
         doAlloc();
         UList<T>::operator=(Foam::zero{});
@@ -206,10 +213,8 @@ Foam::List<T>::List(List<T>& list, bool reuse)
         this->v_ = list.v_;
         list.v_ = nullptr;
         list.size_ = 0;
-        return;
     }
-
-    if (this->size_)
+    else if (this->size_ > 0)
     {
         doAlloc();
         UList<T>::deepCopy(list);
@@ -316,7 +321,13 @@ template<class T>
 void Foam::List<T>::resize(const label len, const T& val)
 {
     const label oldLen = this->size_;
-    this->doResize(len);
+
+    if (oldLen == len)
+    {
+        return;
+    }
+
+    this->resize_copy(oldLen, len);
 
     // Fill trailing part with new values
     if (oldLen < this->size_)
diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H
index 8f2d96a99f3..5c9d7d1c8f3 100644
--- a/src/OpenFOAM/containers/Lists/List/List.H
+++ b/src/OpenFOAM/containers/Lists/List/List.H
@@ -93,10 +93,6 @@ class List
         template<class ListType, class ListIndices>
         inline void copyList(const ListType& list, const ListIndices& indices);
 
-        //- Change allocation size of List, retaining old contents.
-        //  Backend for resize
-        void doResize(const label len);
-
         //- Construct given begin/end iterators and number of elements
         //  Since the size is provided, the end iterator is actually ignored.
         template<class InputIterator>
@@ -118,6 +114,16 @@ class List
         void setCapacity_nocopy(const label len) { resize_nocopy(len); }
 
 
+protected:
+
+    // Protected Member Functions
+
+        //- Low-level resizing (backend for resize).
+        //- Change allocation size of list, retaining the first count contents.
+        //  \note Only uses a limited number of internal checks.
+        void resize_copy(const label count, const label len);
+
+
 public:
 
     // Related types
diff --git a/src/OpenFOAM/containers/Lists/List/ListI.H b/src/OpenFOAM/containers/Lists/List/ListI.H
index bdb510f8374..228df08392b 100644
--- a/src/OpenFOAM/containers/Lists/List/ListI.H
+++ b/src/OpenFOAM/containers/Lists/List/ListI.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.
@@ -102,7 +102,7 @@ inline Foam::List<T>::List
 :
     UList<T>(nullptr, len)
 {
-    if (this->size_)
+    if (len > 0)
     {
         doAlloc();
 
@@ -149,9 +149,9 @@ namespace Foam
 {
     // Template specialization for bool. Fills new entries with false
     template<>
-    inline void List<bool>::resize(const label newLen)
+    inline void List<bool>::resize(const label len)
     {
-        this->resize(newLen, false);
+        this->resize(len, false);
     }
 }
 
@@ -159,7 +159,10 @@ namespace Foam
 template<class T>
 inline void Foam::List<T>::resize(const label len)
 {
-    this->doResize(len);
+    if (this->size_ != len)
+    {
+        this->resize_copy(this->size_, len);
+    }
 }
 
 
@@ -269,7 +272,6 @@ inline void Foam::List<T>::push_back(const IndirectListBase<T, Addr>& list)
 
     const label idx = this->size();
     const label n = list.size();
-
     resize(idx + n);
 
     auto iter = this->begin(idx);
diff --git a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H
index ee33bbef2d2..f55ee7e022c 100644
--- a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H
+++ b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynList.H
@@ -76,9 +76,12 @@ public:
         //- Default construct
         inline constexpr PtrDynList() noexcept;
 
-        //- Construct with given capacity.
+        //- Construct with given initial capacity
         inline explicit PtrDynList(const label len);
 
+        //- Construct with given size and capacity
+        inline explicit PtrDynList(const std::pair<label,label>& sizing);
+
         //- Copy construct using 'clone()' method on each element
         inline PtrDynList(const PtrDynList<T, SizeMin>& list);
 
@@ -107,6 +110,10 @@ public:
         //- Size of the underlying storage.
         label capacity() const noexcept { return capacity_; }
 
+        //- Change the value for the list capacity directly (ADVANCED, UNSAFE)
+        //- Does not perform any memory management or resizing.
+        void setCapacity_unsafe(const label len) noexcept { capacity_ = len; }
+
         //- Reserve allocation space for at least this size.
         inline void reserve(const label len);
 
@@ -138,8 +145,8 @@ public:
         //  \note when empty() it will delete any allocated memory.
         inline void shrink_unsafe();
 
-        //- Calls shrink_to_fit()
-        void shrink() { shrink_to_fit(); }
+        //- Alias for shrink_to_fit()
+        void shrink() { this->shrink_to_fit(); }
 
 
     // Edit
diff --git a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H
index fccedeccfbd..79763cf3985 100644
--- a/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H
+++ b/src/OpenFOAM/containers/PtrLists/PtrDynList/PtrDynListI.H
@@ -49,6 +49,19 @@ inline Foam::PtrDynList<T, SizeMin>::PtrDynList(const label len)
 }
 
 
+template<class T, int SizeMin>
+inline Foam::PtrDynList<T, SizeMin>::PtrDynList
+(
+    const std::pair<label,label>& sizing
+)
+:
+    PtrList<T>(std::max(sizing.first, sizing.second)),
+    capacity_(PtrList<T>::size())
+{
+    PtrList<T>::setAddressableSize(sizing.first);
+}
+
+
 template<class T, int SizeMin>
 inline Foam::PtrDynList<T, SizeMin>::PtrDynList
 (
@@ -220,8 +233,7 @@ inline void Foam::PtrDynList<T, SizeMin>::shrink_to_fit()
     const label currLen = PtrList<T>::size();
     if (currLen < capacity_)
     {
-        // Adjust addressable size to trigger proper resizing
-        PtrList<T>::setAddressableSize(currLen+1);
+        PtrList<T>::setAddressableSize(capacity_);
         PtrList<T>::resize(currLen);
         capacity_ = PtrList<T>::size();
     }
diff --git a/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H b/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H
index 72c83892780..89e4a9688ab 100644
--- a/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H
+++ b/src/OpenFOAM/containers/PtrLists/PtrList/PtrList.H
@@ -249,7 +249,7 @@ public:
         }
 
         //- Same as resize()
-        void setSize(const label newLen) { this->resize(newLen); }
+        void setSize(const label n) { this->resize(n); }
 
         //- Move append an element to the end of the list
         //FOAM_DEPRECATED_FOR(2022-10, "push_back()")
diff --git a/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H b/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H
index 5f73c83e117..7451c5ffdef 100644
--- a/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H
+++ b/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H
@@ -29,6 +29,7 @@ Class
 
 Description
     Dynamically sized Field.
+    Similar to DynamicList, but inheriting from a Field instead of a List.
 
 SourceFiles
     DynamicFieldI.H
@@ -95,15 +96,6 @@ class DynamicField
 
 public:
 
-    // Static Member Functions
-
-        //- Return a null DynamicField (reference to a nullObject).
-        static const DynamicField<T, SizeMin>& null() noexcept
-        {
-            return NullObjectRef<DynamicField<T, SizeMin>>();
-        }
-
-
     // Constructors
 
         //- Default construct, an empty field without allocation.
@@ -112,11 +104,14 @@ public:
         //- Construct empty field with given initial capacity
         inline explicit DynamicField(const label initialCapacity);
 
+        //- Construct with given size and capacity
+        inline explicit DynamicField(const std::pair<label,label>& sizing);
+
         //- Construct given size and initial value
         inline DynamicField(const label len, const T& val);
 
         //- Construct given size and initial value of zero
-        inline DynamicField(const label len, const Foam::zero);
+        inline DynamicField(const label len, Foam::zero);
 
         //- Copy construct
         inline DynamicField(const DynamicField<T, SizeMin>& list);
@@ -222,7 +217,7 @@ public:
 
         //- Change the value for the list capacity directly (ADVANCED, UNSAFE)
         //- Does not perform any memory management or resizing.
-        inline void setCapacity_unsafe(const label len) noexcept;
+        void setCapacity_unsafe(const label len) noexcept { capacity_ = len; }
 
         //- Reserve allocation space for at least this size, allocating new
         //- space if required and \em retaining old content.
@@ -248,21 +243,18 @@ public:
         //  setting values (as per List usage).
         inline void resize(const label len);
 
-        //- Alter addressable size and fill new space with constant value
+        //- Alter addressable size and fill \em new entries with constant value
         inline void resize(const label len, const T& val);
 
+        //- Alter addressable size and set val for \em all addressed entries
+        inline void resize_fill(const label len, const T& val);
+
         //- Alter addressable list size, allocating new space if required
         //- \em without necessarily recovering old content.
         //  If no reallocation is required, the contents remain untouched.
         //  Otherwise all entries will be uninitialized.
         inline void resize_nocopy(const label len);
 
-        //- Alias for resize()
-        void setSize(const label n) { this->resize(n); }
-
-        //- Alias for resize()
-        void setSize(const label n, const T& val) { this->resize(n, val); }
-
         //- Clear the addressed list, i.e. set the size to zero.
         //  Allocated size does not change
         inline void clear() noexcept;
@@ -278,9 +270,6 @@ public:
         //  \note when empty() it will delete any allocated memory.
         inline void shrink_unsafe();
 
-        //- Calls shrink_to_fit() and returns a reference to the DynamicField.
-        inline DynamicField<T, SizeMin>& shrink();
-
 
     // Edit
 
@@ -289,11 +278,11 @@ public:
 
         //- Swap content, independent of sizing parameter
         template<int AnySizeMin>
-        inline void swap(DynamicField<T, AnySizeMin>& other);
+        inline void swap(DynamicField<T, AnySizeMin>& other) noexcept;
 
         //- Swap content with DynamicList, independent of sizing parameter
         template<int AnySizeMin>
-        inline void swap(DynamicList<T, AnySizeMin>& other);
+        inline void swap(DynamicList<T, AnySizeMin>& other) noexcept;
 
         //- Transfer the parameter contents into this
         inline void transfer(List<T>& list);
@@ -311,7 +300,7 @@ public:
         template<class... Args>
         inline T& emplace_back(Args&&... args);
 
-        //- Copy append an element at the end of the list
+        //- Copy append an element to the end of the list
         inline void push_back(const T& val);
 
         //- Move append an element
@@ -340,7 +329,7 @@ public:
         inline void operator=(const T& val);
 
         //- Assign addressed entries to zero
-        inline void operator=(const Foam::zero);
+        inline void operator=(Foam::zero);
 
         //- Copy assignment
         inline void operator=(const UList<T>& list);
@@ -392,6 +381,20 @@ public:
 
     // Housekeeping
 
+        //- Alias for resize()
+        void setSize(const label n) { this->resize(n); }
+
+        //- Alias for resize()
+        void setSize(const label n, const T& val) { this->resize(n, val); }
+
+        //- Calls shrink_to_fit() and returns a reference to the DynamicField.
+        //FOAM_DEPRECATED_FOR(2025-04, "shrink_to_fit()")
+        DynamicField<T, SizeMin>& shrink()
+        {
+            this->shrink_to_fit();
+            return *this;
+        }
+
         //- Append an element at the end of the list
         //FOAM_DEPRECATED_FOR(2022-10, "push_back()")
         void append(const T& val) { this->push_back(val); }
diff --git a/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H b/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H
index 18012d91f2b..1b5b6fd69d1 100644
--- a/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H
+++ b/src/OpenFOAM/fields/Fields/DynamicField/DynamicFieldI.H
@@ -40,7 +40,7 @@ inline void Foam::DynamicField<T, SizeMin>::doAssignDynList
     if (capacity_ < len)
     {
         // Needs more space for the copy operation
-        List<T>::setAddressableSize(capacity_);  // Use entire space
+        List<T>::setAddressableSize(capacity_);
         List<T>::resize_nocopy(len);
         capacity_ = List<T>::size();
     }
@@ -66,19 +66,14 @@ inline void Foam::DynamicField<T, SizeMin>::doCapacity
     // Addressable length, possibly truncated by new capacity
     const label currLen = Foam::min(List<T>::size(), newCapacity);
 
-    // Corner case - see comments in DynamicList doCapacity
-    if (List<T>::size() == newCapacity)
-    {
-        List<T>::setAddressableSize(currLen+1);
-    }
-
+    List<T>::setAddressableSize(capacity_);
     if (nocopy)
     {
         List<T>::resize_nocopy(newCapacity);
     }
     else
     {
-        List<T>::resize(newCapacity);
+        List<T>::resize_copy(currLen, newCapacity);
     }
 
     capacity_ = List<T>::size();
@@ -147,6 +142,19 @@ inline Foam::DynamicField<T, SizeMin>::DynamicField(const label initialCapacity)
 }
 
 
+template<class T, int SizeMin>
+inline Foam::DynamicField<T, SizeMin>::DynamicField
+(
+    const std::pair<label,label>& sizing
+)
+:
+    Field<T>(std::max(sizing.first, sizing.second)),
+    capacity_(Field<T>::size())
+{
+    List<T>::setAddressableSize(sizing.first);
+}
+
+
 template<class T, int SizeMin>
 inline Foam::DynamicField<T, SizeMin>::DynamicField
 (
@@ -163,7 +171,7 @@ template<class T, int SizeMin>
 inline Foam::DynamicField<T, SizeMin>::DynamicField
 (
     const label len,
-    const Foam::zero
+    Foam::zero
 )
 :
     Field<T>(len, Foam::zero{}),
@@ -423,16 +431,6 @@ inline void Foam::DynamicField<T, SizeMin>::setCapacity_nocopy
 }
 
 
-template<class T, int SizeMin>
-inline void Foam::DynamicField<T, SizeMin>::setCapacity_unsafe
-(
-    const label len
-) noexcept
-{
-    capacity_ = len;
-}
-
-
 template<class T, int SizeMin>
 inline void Foam::DynamicField<T, SizeMin>::reserve
 (
@@ -491,6 +489,18 @@ inline void Foam::DynamicField<T, SizeMin>::resize_nocopy
 }
 
 
+template<class T, int SizeMin>
+inline void Foam::DynamicField<T, SizeMin>::resize_fill
+(
+    const label len,
+    const T& val
+)
+{
+    this->doResize(true, len);  // nocopy = true
+    UList<T>::operator=(val);
+}
+
+
 template<class T, int SizeMin>
 inline void Foam::DynamicField<T, SizeMin>::resize
 (
@@ -534,8 +544,7 @@ inline void Foam::DynamicField<T, SizeMin>::shrink_to_fit()
 
     if (currLen < capacity_)
     {
-        // Adjust addressable size to trigger proper resizing
-        List<T>::setAddressableSize(currLen+1);
+        List<T>::setAddressableSize(capacity_);
         List<T>::resize(currLen);
         capacity_ = List<T>::size();
     }
@@ -554,15 +563,6 @@ inline void Foam::DynamicField<T, SizeMin>::shrink_unsafe()
 }
 
 
-template<class T, int SizeMin>
-inline Foam::DynamicField<T, SizeMin>&
-Foam::DynamicField<T, SizeMin>::shrink()
-{
-    this->shrink_to_fit();
-    return *this;
-}
-
-
 template<class T, int SizeMin>
 inline void
 Foam::DynamicField<T, SizeMin>::swap(List<T>& list)
@@ -592,7 +592,7 @@ template<int AnySizeMin>
 inline void Foam::DynamicField<T, SizeMin>::swap
 (
     DynamicField<T, AnySizeMin>& other
-)
+) noexcept
 {
     if
     (
@@ -616,7 +616,7 @@ template<int AnySizeMin>
 inline void Foam::DynamicField<T, SizeMin>::swap
 (
     DynamicList<T, AnySizeMin>& other
-)
+) noexcept
 {
     if
     (
@@ -822,7 +822,7 @@ inline void Foam::DynamicField<T, SizeMin>::operator=
 template<class T, int SizeMin>
 inline void Foam::DynamicField<T, SizeMin>::operator=
 (
-    const Foam::zero
+    Foam::zero
 )
 {
     UList<T>::operator=(Foam::zero{});
-- 
GitLab


From 1d62b6274e264b442704a965d91101458201afa4 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Thu, 10 Apr 2025 15:57:43 +0200
Subject: [PATCH 2/2] COMP: add <numeric> to stdFoam.H

- useful to have std::reduce(), std::transform_reduce() available in
  more places, so treat like <algorithm> and include in "stdFoam.H"

STYLE: add 'stricter' detection markers for cast of SubList to List etc.

STYLE: remove 'const' qualifier from Foam:one/Foam::zero (in Field)
---
 applications/test/FixedList/Make/files               |  2 +-
 .../{Test-FixedList.C => Test-FixedList.cxx}         |  1 -
 applications/test/List/Test-List.cxx                 |  1 -
 applications/test/ListRead1/Make/files               |  2 +-
 applications/test/ListRead1/Test-ListRead1.C         |  1 -
 applications/test/SubField/Make/files                |  2 +-
 .../SubField/{Test-SubField.C => Test-SubField.cxx}  |  1 -
 applications/test/charList/Make/files                |  2 +-
 .../charList/{Test-charList.C => Test-charList.cxx}  |  2 --
 applications/test/checkIOspeed/Test-checkIOspeed.cxx |  2 --
 .../mesh/manipulation/stitchMesh/stitchMesh.C        |  1 -
 src/OpenFOAM/containers/Lists/List/SubList.H         |  6 +++++-
 src/OpenFOAM/containers/Lists/List/SubListI.H        |  7 -------
 src/OpenFOAM/containers/Lists/List/UList.H           |  2 +-
 src/OpenFOAM/expressions/value/exprValue.H           |  2 +-
 src/OpenFOAM/expressions/value/exprValueFieldTag.H   |  2 +-
 .../DimensionedField/DimensionedFieldFunctions.C     |  6 +++---
 .../DimensionedField/DimensionedFieldFunctions.H     |  6 +++---
 .../fields/FieldFields/FieldField/FieldField.C       |  2 +-
 .../fields/FieldFields/FieldField/FieldField.H       |  2 +-
 src/OpenFOAM/fields/Fields/Field/Field.H             | 12 ++++++------
 src/OpenFOAM/fields/Fields/Field/FieldI.H            | 12 +++++-------
 src/OpenFOAM/fields/Fields/Field/SubField.H          | 10 ++++++++--
 src/OpenFOAM/fields/Fields/Field/SubFieldI.H         |  9 +--------
 .../GeometricField/GeometricFieldFunctions.C         |  6 +++---
 .../GeometricField/GeometricFieldFunctions.H         |  6 +++---
 src/OpenFOAM/include/stdFoam.H                       |  3 ++-
 .../matrices/DiagonalMatrix/DiagonalMatrix.H         |  1 -
 src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.H    |  1 -
 .../lduMatrix/solvers/GAMG/GAMGSolverSolve.C         | 11 +++++------
 src/OpenFOAM/meshes/boundBox/boundBox.H              |  4 ++--
 src/OpenFOAM/meshes/boundBox/boundBoxI.H             |  4 ++--
 src/OpenFOAM/meshes/ijkMesh/IjkField.H               |  4 ++--
 src/OpenFOAM/meshes/ijkMesh/IjkFieldI.H              |  6 +++---
 .../meshes/polyMesh/syncTools/syncToolsTemplates.C   |  8 ++++++--
 src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H      |  2 +-
 src/OpenFOAM/meshes/treeBoundBox/treeBoundBoxI.H     |  4 ++--
 src/OpenFOAM/primitives/Scalar/scalarImpl.H          |  2 +-
 src/OpenFOAM/primitives/ranges/MinMax/MinMaxOps.H    |  2 +-
 src/conversion/vtk/adaptor/foamVtkToolsI.H           |  2 --
 src/fileFormats/ensight/part/faces/ensightFaces.C    | 10 +++++-----
 41 files changed, 78 insertions(+), 93 deletions(-)
 rename applications/test/FixedList/{Test-FixedList.C => Test-FixedList.cxx} (99%)
 rename applications/test/SubField/{Test-SubField.C => Test-SubField.cxx} (99%)
 rename applications/test/charList/{Test-charList.C => Test-charList.cxx} (99%)

diff --git a/applications/test/FixedList/Make/files b/applications/test/FixedList/Make/files
index dcfee8af133..cd58141078e 100644
--- a/applications/test/FixedList/Make/files
+++ b/applications/test/FixedList/Make/files
@@ -1,3 +1,3 @@
-Test-FixedList.C
+Test-FixedList.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-FixedList
diff --git a/applications/test/FixedList/Test-FixedList.C b/applications/test/FixedList/Test-FixedList.cxx
similarity index 99%
rename from applications/test/FixedList/Test-FixedList.C
rename to applications/test/FixedList/Test-FixedList.cxx
index e77190a7939..5f8a1034417 100644
--- a/applications/test/FixedList/Test-FixedList.C
+++ b/applications/test/FixedList/Test-FixedList.cxx
@@ -41,7 +41,6 @@ See also
 #include "List.H"
 #include "IPstream.H"
 #include "OPstream.H"
-#include <numeric>
 
 using namespace Foam;
 
diff --git a/applications/test/List/Test-List.cxx b/applications/test/List/Test-List.cxx
index 96571f642cb..0962997830c 100644
--- a/applications/test/List/Test-List.cxx
+++ b/applications/test/List/Test-List.cxx
@@ -54,7 +54,6 @@ See also
 #include "ListPolicy.H"
 
 #include <list>
-#include <numeric>
 #include <functional>
 
 // see issue #2083
diff --git a/applications/test/ListRead1/Make/files b/applications/test/ListRead1/Make/files
index da3cc22d196..8631d227f0e 100644
--- a/applications/test/ListRead1/Make/files
+++ b/applications/test/ListRead1/Make/files
@@ -1,3 +1,3 @@
-Test-ListRead1.C
+Test-ListRead1.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-ListRead1
diff --git a/applications/test/ListRead1/Test-ListRead1.C b/applications/test/ListRead1/Test-ListRead1.C
index d7417235b4e..aac211e2da6 100644
--- a/applications/test/ListRead1/Test-ListRead1.C
+++ b/applications/test/ListRead1/Test-ListRead1.C
@@ -50,7 +50,6 @@ Description
 #include "ListPolicy.H"
 
 #include <list>
-#include <numeric>
 #include <functional>
 
 using namespace Foam;
diff --git a/applications/test/SubField/Make/files b/applications/test/SubField/Make/files
index 406ae415312..9e8f8ac4bbc 100644
--- a/applications/test/SubField/Make/files
+++ b/applications/test/SubField/Make/files
@@ -1,3 +1,3 @@
-Test-SubField.C
+Test-SubField.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-SubField
diff --git a/applications/test/SubField/Test-SubField.C b/applications/test/SubField/Test-SubField.cxx
similarity index 99%
rename from applications/test/SubField/Test-SubField.C
rename to applications/test/SubField/Test-SubField.cxx
index bed02ecacb5..17a41f14f38 100644
--- a/applications/test/SubField/Test-SubField.C
+++ b/applications/test/SubField/Test-SubField.cxx
@@ -38,7 +38,6 @@ Description
 #include "SubField.H"
 #include "labelRange.H"
 #include "ListOps.H"
-#include <numeric>
 
 using namespace Foam;
 
diff --git a/applications/test/charList/Make/files b/applications/test/charList/Make/files
index e7b5eba75bf..f3f0e233d57 100644
--- a/applications/test/charList/Make/files
+++ b/applications/test/charList/Make/files
@@ -1,3 +1,3 @@
-Test-charList.C
+Test-charList.cxx
 
 EXE = $(FOAM_USER_APPBIN)/Test-charList
diff --git a/applications/test/charList/Test-charList.C b/applications/test/charList/Test-charList.cxx
similarity index 99%
rename from applications/test/charList/Test-charList.C
rename to applications/test/charList/Test-charList.cxx
index 32e98110930..8a480a287b5 100644
--- a/applications/test/charList/Test-charList.C
+++ b/applications/test/charList/Test-charList.cxx
@@ -43,8 +43,6 @@ Description
 #include "SubList.H"
 #include "FlatOutput.H"
 
-#include <numeric>
-
 using namespace Foam;
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/applications/test/checkIOspeed/Test-checkIOspeed.cxx b/applications/test/checkIOspeed/Test-checkIOspeed.cxx
index a92159dde3b..5db748b01c6 100644
--- a/applications/test/checkIOspeed/Test-checkIOspeed.cxx
+++ b/applications/test/checkIOspeed/Test-checkIOspeed.cxx
@@ -50,8 +50,6 @@ Description
 #include "SliceStreamRepo.H"
 #endif
 
-#include <numeric>
-
 using namespace Foam;
 
 
diff --git a/applications/utilities/mesh/manipulation/stitchMesh/stitchMesh.C b/applications/utilities/mesh/manipulation/stitchMesh/stitchMesh.C
index 8f0ea89dc24..b009297bde0 100644
--- a/applications/utilities/mesh/manipulation/stitchMesh/stitchMesh.C
+++ b/applications/utilities/mesh/manipulation/stitchMesh/stitchMesh.C
@@ -73,7 +73,6 @@ Description
 #include "perfectInterface.H"
 #include "IOobjectList.H"
 #include "ReadFields.H"
-#include <numeric>
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
diff --git a/src/OpenFOAM/containers/Lists/List/SubList.H b/src/OpenFOAM/containers/Lists/List/SubList.H
index 2cd0e10c18e..ba7d320c670 100644
--- a/src/OpenFOAM/containers/Lists/List/SubList.H
+++ b/src/OpenFOAM/containers/Lists/List/SubList.H
@@ -172,7 +172,11 @@ public:
     // Member Operators
 
         //- Allow cast to a const List\<T\>&
-        inline operator const Foam::List<T>&() const;
+        FOAM_DEPRECATED_STRICTER(2025-04, "dereference as SubList, not List?")
+        operator const Foam::List<T>&() const
+        {
+            return *reinterpret_cast<const List<T>*>(this);
+        }
 
         //- Copy assign entries (deep copy) from given sub-list.
         //- Sizes must match!
diff --git a/src/OpenFOAM/containers/Lists/List/SubListI.H b/src/OpenFOAM/containers/Lists/List/SubListI.H
index 1bec82958eb..567fa32f251 100644
--- a/src/OpenFOAM/containers/Lists/List/SubListI.H
+++ b/src/OpenFOAM/containers/Lists/List/SubListI.H
@@ -214,13 +214,6 @@ inline Foam::UList<T>& Foam::SubList<T>::reset
 
 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
 
-template<class T>
-inline Foam::SubList<T>::operator const Foam::List<T>&() const
-{
-    return *reinterpret_cast<const List<T>*>(this);
-}
-
-
 template<class T>
 inline void Foam::SubList<T>::operator=(const SubList<T>& list)
 {
diff --git a/src/OpenFOAM/containers/Lists/List/UList.H b/src/OpenFOAM/containers/Lists/List/UList.H
index 2af60648ff3..0c54fe8a597 100644
--- a/src/OpenFOAM/containers/Lists/List/UList.H
+++ b/src/OpenFOAM/containers/Lists/List/UList.H
@@ -427,7 +427,7 @@ public:
         //- Allow cast to a const List<T>&.
         //  \note Marked as "strictly" deprecated.
         //  Currently (2025-04) code still depends on this cast.
-        FOAM_DEPRECATED_STRICTER(2025-04, "dereference as UList, not List")
+        FOAM_DEPRECATED_STRICTER(2025-04, "dereference as UList, not List?")
         operator const Foam::List<T>&() const
         {
             return *reinterpret_cast<const List<T>*>(this);
diff --git a/src/OpenFOAM/expressions/value/exprValue.H b/src/OpenFOAM/expressions/value/exprValue.H
index 97e057614dd..c65fcb93f16 100644
--- a/src/OpenFOAM/expressions/value/exprValue.H
+++ b/src/OpenFOAM/expressions/value/exprValue.H
@@ -308,7 +308,7 @@ public:
         void operator=(const exprValue& rhs) { deepCopy(rhs); }
 
         //- Assign from zero. Changes value but not type
-        void operator=(const Foam::zero) { fill_zero(); }
+        void operator=(Foam::zero) { fill_zero(); }
 
 
     // Low-level access
diff --git a/src/OpenFOAM/expressions/value/exprValueFieldTag.H b/src/OpenFOAM/expressions/value/exprValueFieldTag.H
index 07f8666e496..b1c3295c4a9 100644
--- a/src/OpenFOAM/expressions/value/exprValueFieldTag.H
+++ b/src/OpenFOAM/expressions/value/exprValueFieldTag.H
@@ -214,7 +214,7 @@ public:
     // Member Operators
 
         //- Assign from zero. Changes value but not type
-        void operator=(const Foam::zero) { value_ = Foam::zero{}; }
+        void operator=(Foam::zero) { value_ = Foam::zero{}; }
 
         //- Compare (uniformity,value) for equality
         bool operator==(const exprValueFieldTag&) const;
diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C
index 362c5a355e6..6328e7c0625 100644
--- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C
+++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.C
@@ -331,7 +331,7 @@ void clamp
 (
     DimensionedField<Type, GeoMesh>& result,
     const DimensionedField<Type, GeoMesh>& f1,
-    const Foam::zero_one
+    Foam::zero_one
 )
 {
     const MinMax<Type> range(Foam::zero_one{});
@@ -345,7 +345,7 @@ tmp<DimensionedField<Type, GeoMesh>>
 clamp
 (
     const DimensionedField<Type, GeoMesh>& f1,
-    const Foam::zero_one
+    Foam::zero_one
 )
 {
     auto tres =
@@ -367,7 +367,7 @@ tmp<DimensionedField<Type, GeoMesh>>
 clamp
 (
     const tmp<DimensionedField<Type, GeoMesh>>& tf1,
-    const Foam::zero_one
+    Foam::zero_one
 )
 {
     const auto& f1 = tf1();
diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.H
index 32ce17fcf04..b6ad90506ca 100644
--- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.H
+++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctions.H
@@ -149,7 +149,7 @@ void clamp
 (
     DimensionedField<Type, GeoMesh>& result,
     const DimensionedField<Type, GeoMesh>& f1,
-    const Foam::zero_one
+    Foam::zero_one
 );
 
 template<class Type, class GeoMesh>
@@ -157,7 +157,7 @@ tmp<DimensionedField<Type, GeoMesh>>
 clamp
 (
     const DimensionedField<Type, GeoMesh>& f1,
-    const Foam::zero_one
+    Foam::zero_one
 );
 
 template<class Type, class GeoMesh>
@@ -165,7 +165,7 @@ tmp<DimensionedField<Type, GeoMesh>>
 clamp
 (
     const tmp<DimensionedField<Type, GeoMesh>>& tf1,
-    const Foam::zero_one
+    Foam::zero_one
 );
 
 BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clamp)
diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.C b/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.C
index 1cd6a54c6b2..7b21f1d7ea5 100644
--- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.C
+++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.C
@@ -458,7 +458,7 @@ void FieldField<Field, Type>::operator=(const Type& val)
 
 
 template<template<class> class Field, class Type>
-void FieldField<Field, Type>::operator=(const Foam::zero)
+void FieldField<Field, Type>::operator=(Foam::zero)
 {
     forAll(*this, i)
     {
diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.H b/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.H
index f1c9fda937f..6924b0b32bc 100644
--- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.H
+++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.H
@@ -197,7 +197,7 @@ public:
         void operator=(const Type& val);
 
         //- Assign uniform zero
-        void operator=(const Foam::zero);
+        void operator=(Foam::zero);
 
         void operator+=(const FieldField<Field, Type>&);
         void operator+=(const tmp<FieldField<Field, Type>>&);
diff --git a/src/OpenFOAM/fields/Fields/Field/Field.H b/src/OpenFOAM/fields/Fields/Field/Field.H
index 3441a50e0b5..c49292a0663 100644
--- a/src/OpenFOAM/fields/Fields/Field/Field.H
+++ b/src/OpenFOAM/fields/Fields/Field/Field.H
@@ -145,16 +145,16 @@ public:
         inline Field(const label len, const Type& val);
 
         //- Construct given size and initial values of zero
-        inline Field(const label len, const Foam::zero);
+        inline Field(const label len, Foam::zero);
 
         //- Construct with length=1, copying the value as the only content
-        inline Field(const Foam::one, const Type& val);
+        inline Field(Foam::one, const Type& val);
 
         //- Construct with length=1, moving the value as the only content
-        inline Field(const Foam::one, Type&& val);
+        inline Field(Foam::one, Type&& val);
 
         //- Construct with length=1, initializing content to zero
-        inline Field(const Foam::one, const Foam::zero);
+        inline Field(Foam::one, Foam::zero);
 
         //- Copy construct
         inline Field(const Field<Type>& fld);
@@ -276,7 +276,7 @@ public:
         //- and assign its contents to this. The behaviour largely as
         //- described in assign():
         //  - For MUST_READ and key not found: FatalIOError.
-        //  - For LAZY_READ and key not found: initialise field with Zero.
+        //  - For LAZY_READ and key not found: initialise field with zero.
         //  - For NO_READ and key not found: simply size the field.
         //  .
         Field
@@ -508,7 +508,7 @@ public:
         inline void operator=(const Type& val);
 
         //- Assign entries to zero
-        inline void operator=(const Foam::zero);
+        inline void operator=(Foam::zero);
 
         template<class Form, class Cmpt, direction nCmpt>
         void operator=(const VectorSpace<Form,Cmpt,nCmpt>&);
diff --git a/src/OpenFOAM/fields/Fields/Field/FieldI.H b/src/OpenFOAM/fields/Fields/Field/FieldI.H
index 4c34df88b14..6d1bf437dd2 100644
--- a/src/OpenFOAM/fields/Fields/Field/FieldI.H
+++ b/src/OpenFOAM/fields/Fields/Field/FieldI.H
@@ -29,8 +29,6 @@ License
 
 template<class Type>
 inline constexpr Foam::Field<Type>::Field() noexcept
-:
-    List<Type>()
 {}
 
 
@@ -49,28 +47,28 @@ inline Foam::Field<Type>::Field(const label len, const Type& val)
 
 
 template<class Type>
-inline Foam::Field<Type>::Field(const label len, const Foam::zero)
+inline Foam::Field<Type>::Field(const label len, Foam::zero)
 :
     List<Type>(len, Foam::zero{})
 {}
 
 
 template<class Type>
-inline Foam::Field<Type>::Field(const Foam::one, const Type& val)
+inline Foam::Field<Type>::Field(Foam::one, const Type& val)
 :
     List<Type>(Foam::one{}, val)
 {}
 
 
 template<class Type>
-inline Foam::Field<Type>::Field(const Foam::one, Type&& val)
+inline Foam::Field<Type>::Field(Foam::one, Type&& val)
 :
     List<Type>(Foam::one{}, std::move(val))
 {}
 
 
 template<class Type>
-inline Foam::Field<Type>::Field(const Foam::one, const Foam::zero)
+inline Foam::Field<Type>::Field(Foam::one, Foam::zero)
 :
     List<Type>(Foam::one{}, Foam::zero{})
 {}
@@ -209,7 +207,7 @@ inline void Foam::Field<Type>::operator=(const Type& val)
 
 
 template<class Type>
-inline void Foam::Field<Type>::operator=(const Foam::zero)
+inline void Foam::Field<Type>::operator=(Foam::zero)
 {
     List<Type>::operator=(Foam::zero{});
 }
diff --git a/src/OpenFOAM/fields/Fields/Field/SubField.H b/src/OpenFOAM/fields/Fields/Field/SubField.H
index 15e09522a71..be237c924ec 100644
--- a/src/OpenFOAM/fields/Fields/Field/SubField.H
+++ b/src/OpenFOAM/fields/Fields/Field/SubField.H
@@ -136,7 +136,13 @@ public:
     // Member Operators
 
         //- Allow cast to a const Field\<Type\>&
-        inline operator const Foam::Field<Type>&() const;
+        //  \note Marked as "strictly" deprecated.
+        //  Currently (2025-04) code still depends on this cast.
+        FOAM_DEPRECATED_STRICTER(2025-04, "dereference as SubField, not Field?")
+        operator const Foam::Field<Type>&() const
+        {
+            return *reinterpret_cast<const Field<Type>*>(this);
+        }
 
         //- Copy assign via UList operator. Takes linear time.
         inline void operator=(const SubField<Type>&);
@@ -148,7 +154,7 @@ public:
         inline void operator=(const Type& val);
 
         //- Assign all entries to zero
-        inline void operator=(const Foam::zero);
+        inline void operator=(Foam::zero);
 
         //- Copy assign via UList operator. Takes linear time.
         template<class Form, direction Ncmpts>
diff --git a/src/OpenFOAM/fields/Fields/Field/SubFieldI.H b/src/OpenFOAM/fields/Fields/Field/SubFieldI.H
index 235f981da7e..0aff687982e 100644
--- a/src/OpenFOAM/fields/Fields/Field/SubFieldI.H
+++ b/src/OpenFOAM/fields/Fields/Field/SubFieldI.H
@@ -125,13 +125,6 @@ inline Foam::tmp<Foam::Field<Type>> Foam::SubField<Type>::T() const
 
 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
 
-template<class Type>
-inline Foam::SubField<Type>::operator const Foam::Field<Type>&() const
-{
-    return *reinterpret_cast<const Field<Type>*>(this);
-}
-
-
 template<class Type>
 inline void Foam::SubField<Type>::operator=(const SubField<Type>& rhs)
 {
@@ -154,7 +147,7 @@ inline void Foam::SubField<Type>::operator=(const Type& val)
 
 
 template<class Type>
-inline void Foam::SubField<Type>::operator=(const Foam::zero)
+inline void Foam::SubField<Type>::operator=(Foam::zero)
 {
     SubList<Type>::operator=(Foam::zero{});
 }
diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C
index 506942bb915..3336a347217 100644
--- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C
+++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.C
@@ -524,7 +524,7 @@ void clamp
 (
     GeometricField<Type, PatchField, GeoMesh>& result,
     const GeometricField<Type, PatchField, GeoMesh>& f1,
-    const Foam::zero_one
+    Foam::zero_one
 )
 {
     const MinMax<Type> range(Foam::zero_one{});
@@ -544,7 +544,7 @@ tmp<GeometricField<Type, PatchField, GeoMesh>>
 clamp
 (
     const GeometricField<Type, PatchField, GeoMesh>& f1,
-    const Foam::zero_one
+    Foam::zero_one
 )
 {
     auto tres =
@@ -566,7 +566,7 @@ tmp<GeometricField<Type, PatchField, GeoMesh>>
 clamp
 (
     const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1,
-    const Foam::zero_one
+    Foam::zero_one
 )
 {
     const auto& f1 = tf1();
diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H
index 5aab42aae0e..92fe6c87aad 100644
--- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H
+++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldFunctions.H
@@ -287,7 +287,7 @@ void clamp
 (
     GeometricField<Type, PatchField, GeoMesh>& result,
     const GeometricField<Type, PatchField, GeoMesh>& f1,
-    const Foam::zero_one
+    Foam::zero_one
 );
 
 template<class Type, template<class> class PatchField, class GeoMesh>
@@ -295,7 +295,7 @@ tmp<GeometricField<Type, PatchField, GeoMesh>>
 clamp
 (
     const GeometricField<Type, PatchField, GeoMesh>& f1,
-    const Foam::zero_one
+    Foam::zero_one
 );
 
 template<class Type, template<class> class PatchField, class GeoMesh>
@@ -303,7 +303,7 @@ tmp<GeometricField<Type, PatchField, GeoMesh>>
 clamp
 (
     const tmp<GeometricField<Type, PatchField, GeoMesh>>& tf1,
-    const Foam::zero_one
+    Foam::zero_one
 );
 
 BINARY_TYPE_FUNCTION_FS(Type, Type, MinMax<Type>, clamp)
diff --git a/src/OpenFOAM/include/stdFoam.H b/src/OpenFOAM/include/stdFoam.H
index 24cf6c14b30..5878f8e7907 100644
--- a/src/OpenFOAM/include/stdFoam.H
+++ b/src/OpenFOAM/include/stdFoam.H
@@ -24,7 +24,7 @@ License
     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
 
 Description
-    Includes some standard C++ headers, defines global macros and templates
+    Includes some common C++ headers, defines global macros and templates
     used in multiple places by OpenFOAM.
 
 \*---------------------------------------------------------------------------*/
@@ -36,6 +36,7 @@ Description
 #include <initializer_list>
 #include <iterator>  // for std::begin, std::end, ...
 #include <memory>
+#include <numeric>   // for std::iota, std::reduce, ...
 #include <type_traits>
 #include <utility>
 
diff --git a/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.H b/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.H
index 60e985a25e1..017a6adf673 100644
--- a/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.H
+++ b/src/OpenFOAM/matrices/DiagonalMatrix/DiagonalMatrix.H
@@ -43,7 +43,6 @@ SourceFiles
 #define Foam_DiagonalMatrix_H
 
 #include "List.H"
-#include <numeric>
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
diff --git a/src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.H b/src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.H
index 0ef3cd52a11..96f6e53f112 100644
--- a/src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.H
+++ b/src/OpenFOAM/matrices/SquareMatrix/SquareMatrix.H
@@ -45,7 +45,6 @@ SourceFiles
 
 #include "Matrix.H"
 #include "Identity.H"
-#include <numeric>
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGSolverSolve.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGSolverSolve.C
index 5e472755d67..fafaabee130 100644
--- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGSolverSolve.C
+++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGSolverSolve.C
@@ -239,7 +239,7 @@ void Foam::GAMGSolver::Vcycle
                         coarseCorrFields[leveli],
                         const_cast<solveScalarField&>
                         (
-                            ACf.operator const solveScalarField&()
+                            static_cast<const solveScalarField&>(ACf)
                         ),
                         matrixLevels_[leveli],
                         interfaceLevelsBouCoeffs_[leveli],
@@ -346,11 +346,10 @@ void Foam::GAMGSolver::Vcycle
                 scratch1,
                 coarseCorrFields[leveli].size()
             );
-            solveScalarField& ACfRef =
-                const_cast<solveScalarField&>
-                (
-                    ACf.operator const solveScalarField&()
-                );
+            auto& ACfRef = const_cast<solveScalarField&>
+            (
+                static_cast<const solveScalarField&>(ACf)
+            );
 
             if (interpolateCorrection_)
             {
diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.H b/src/OpenFOAM/meshes/boundBox/boundBox.H
index 554c93285cf..109a53ff792 100644
--- a/src/OpenFOAM/meshes/boundBox/boundBox.H
+++ b/src/OpenFOAM/meshes/boundBox/boundBox.H
@@ -164,7 +164,7 @@ public:
         inline explicit boundBox(const point& p);
 
         //- Construct a 0/1 unit bounding box
-        inline explicit boundBox(const Foam::zero_one);
+        inline explicit boundBox(Foam::zero_one);
 
         //- Construct from bound box min/max points
         inline boundBox(const point& min, const point& max);
@@ -295,7 +295,7 @@ public:
             inline void reset();
 
             //- Reset to a 0/1 unit bounding box
-            inline void reset(const Foam::zero_one);
+            inline void reset(Foam::zero_one);
 
             //- Reset min/max to be identical to the specified point
             inline void reset(const point& pt);
diff --git a/src/OpenFOAM/meshes/boundBox/boundBoxI.H b/src/OpenFOAM/meshes/boundBox/boundBoxI.H
index 4b900ae1c53..147944fe860 100644
--- a/src/OpenFOAM/meshes/boundBox/boundBoxI.H
+++ b/src/OpenFOAM/meshes/boundBox/boundBoxI.H
@@ -112,7 +112,7 @@ inline Foam::boundBox::boundBox()
 {}
 
 
-inline Foam::boundBox::boundBox(const Foam::zero_one)
+inline Foam::boundBox::boundBox(Foam::zero_one)
 :
     min_(point::zero),
     max_(point::one)
@@ -306,7 +306,7 @@ inline void Foam::boundBox::reset()
 }
 
 
-inline void Foam::boundBox::reset(const Foam::zero_one)
+inline void Foam::boundBox::reset(Foam::zero_one)
 {
     min_ = point::zero;
     max_ = point::one;
diff --git a/src/OpenFOAM/meshes/ijkMesh/IjkField.H b/src/OpenFOAM/meshes/ijkMesh/IjkField.H
index f7e0b284495..8ce84d24823 100644
--- a/src/OpenFOAM/meshes/ijkMesh/IjkField.H
+++ b/src/OpenFOAM/meshes/ijkMesh/IjkField.H
@@ -81,7 +81,7 @@ public:
         inline IjkField(const labelVector& ijk, const Type& val);
 
         //- Construct with sizing information and initial values of zero
-        inline IjkField(const labelVector& ijk, const Foam::zero);
+        inline IjkField(const labelVector& ijk, Foam::zero);
 
         //- Copy construct from components
         inline IjkField(const labelVector& ijk, const UList<Type>& list);
@@ -118,7 +118,7 @@ public:
         //- Clear dimensions and field
         inline void clear();
 
-        //- Change dimensions. Fill new values with Zero
+        //- Change dimensions. Fill new values with zero
         void resize(const labelVector& newSizes);
 
         //- Change dimensions
diff --git a/src/OpenFOAM/meshes/ijkMesh/IjkFieldI.H b/src/OpenFOAM/meshes/ijkMesh/IjkFieldI.H
index 45c9afade78..97c44b22b0a 100644
--- a/src/OpenFOAM/meshes/ijkMesh/IjkFieldI.H
+++ b/src/OpenFOAM/meshes/ijkMesh/IjkFieldI.H
@@ -75,7 +75,7 @@ template<class Type>
 inline Foam::IjkField<Type>::IjkField
 (
     const labelVector& ijk,
-    const Foam::zero
+    Foam::zero
 )
 :
     Field<Type>(cmptProduct(ijk), Foam::zero{}),
@@ -101,7 +101,7 @@ inline Foam::IjkField<Type>::IjkField
             << nl << nl;
         #endif
 
-        Field<Type>::resize(ijk_.size(), Zero);
+        Field<Type>::resize(ijk_.size(), Foam::zero{});
     }
 }
 
@@ -124,7 +124,7 @@ inline Foam::IjkField<Type>::IjkField
             << nl << nl;
         #endif
 
-        Field<Type>::resize(ijk_.size(), Zero);
+        Field<Type>::resize(ijk_.size(), Foam::zero{});
     }
 }
 
diff --git a/src/OpenFOAM/meshes/polyMesh/syncTools/syncToolsTemplates.C b/src/OpenFOAM/meshes/polyMesh/syncTools/syncToolsTemplates.C
index a0a55385e45..f1b20cb1a35 100644
--- a/src/OpenFOAM/meshes/polyMesh/syncTools/syncToolsTemplates.C
+++ b/src/OpenFOAM/meshes/polyMesh/syncTools/syncToolsTemplates.C
@@ -1134,8 +1134,12 @@ void Foam::syncTools::syncBoundaryFaceList
                         pp.size(),
                         pp.start()-boundaryOffset
                     );
-                    const List<T>& fakeList = recvFld;
-                    top(procPatch, const_cast<List<T>&>(fakeList));
+
+                    auto& fakeList = const_cast<List<T>&>
+                    (
+                        static_cast<const List<T>&>(recvFld)
+                    );
+                    top(procPatch, fakeList);
 
                     SubList<T> patchValues
                     (
diff --git a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H
index a30a872250a..26d24f1f497 100644
--- a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H
+++ b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.H
@@ -202,7 +202,7 @@ public:
     // Constructors
 
         //- Construct a 0/1 unit bounding box
-        inline explicit treeBoundBox(const Foam::zero_one);
+        inline explicit treeBoundBox(Foam::zero_one);
 
         //- Construct a bounding box containing a single initial point
         inline explicit treeBoundBox(const point& p);
diff --git a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBoxI.H b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBoxI.H
index 08bff3acfa2..5315c457024 100644
--- a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBoxI.H
+++ b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBoxI.H
@@ -31,9 +31,9 @@ License
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-inline Foam::treeBoundBox::treeBoundBox(const Foam::zero_one)
+inline Foam::treeBoundBox::treeBoundBox(Foam::zero_one)
 :
-    boundBox(zero_one{})
+    boundBox(Foam::zero_one{})
 {}
 
 
diff --git a/src/OpenFOAM/primitives/Scalar/scalarImpl.H b/src/OpenFOAM/primitives/Scalar/scalarImpl.H
index 0d1564dde56..cde30b8c7fd 100644
--- a/src/OpenFOAM/primitives/Scalar/scalarImpl.H
+++ b/src/OpenFOAM/primitives/Scalar/scalarImpl.H
@@ -292,7 +292,7 @@ inline bool notEqual(const Scalar a, const Scalar b)
 
 
 //- Clamp scalar value to a 0-1 range
-inline Scalar clamp(const Scalar val, const Foam::zero_one)
+inline Scalar clamp(const Scalar val, Foam::zero_one)
 {
     return (val < 0) ? 0 : (1 < val) ? 1 : val;
 }
diff --git a/src/OpenFOAM/primitives/ranges/MinMax/MinMaxOps.H b/src/OpenFOAM/primitives/ranges/MinMax/MinMaxOps.H
index 71e3632bfc6..26464e0d16c 100644
--- a/src/OpenFOAM/primitives/ranges/MinMax/MinMaxOps.H
+++ b/src/OpenFOAM/primitives/ranges/MinMax/MinMaxOps.H
@@ -84,7 +84,7 @@ struct clampOp
     {}
 
     //- Construct as 0-1 min/max range
-    clampOp(const Foam::zero_one)
+    clampOp(Foam::zero_one)
     :
         clampOp(MinMax<T>(Foam::zero_one{}))
     {}
diff --git a/src/conversion/vtk/adaptor/foamVtkToolsI.H b/src/conversion/vtk/adaptor/foamVtkToolsI.H
index aa2da4eeb21..435845f3b76 100644
--- a/src/conversion/vtk/adaptor/foamVtkToolsI.H
+++ b/src/conversion/vtk/adaptor/foamVtkToolsI.H
@@ -25,8 +25,6 @@ License
 
 \*---------------------------------------------------------------------------*/
 
-#include <numeric>
-
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 inline Foam::UList<uint8_t> Foam::vtk::Tools::asUList
diff --git a/src/fileFormats/ensight/part/faces/ensightFaces.C b/src/fileFormats/ensight/part/faces/ensightFaces.C
index 4b41a67fd20..393182e2851 100644
--- a/src/fileFormats/ensight/part/faces/ensightFaces.C
+++ b/src/fileFormats/ensight/part/faces/ensightFaces.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2016-2022 OpenCFD Ltd.
+    Copyright (C) 2016-2025 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -193,22 +193,22 @@ void Foam::ensightFaces::sort()
         if (!sub.empty())
         {
             SubList<label> ids(sub, addressing());
-            labelList order(Foam::sortedOrder(ids));
+            const labelList order(Foam::sortedOrder(ids));
 
-            ids = reorder<labelList>(order, ids);
+            ids = UIndirectList<label>(ids, order).list();
 
             // Sort flip map as well
             if (!flipMap_.empty())
             {
                 SubList<bool> flips(flipMap_, sub);
-                flips = reorder<boolList>(order, flips);
+                flips = UIndirectList<bool>(flips, order).list();
             }
 
             // Sort face ordering as well
             if (!faceOrder_.empty())
             {
                 SubList<label> faceOrder(faceOrder_, sub);
-                faceOrder = reorder<labelList>(order, faceOrder);
+                faceOrder = UIndirectList<label>(faceOrder, order).list();
             }
         }
     }
-- 
GitLab