From cb9732204dce97182276c0b9503acbc619596ac9 Mon Sep 17 00:00:00 2001
From: Henry Weller <http://cfd.direct>
Date: Tue, 26 Apr 2016 20:44:55 +0100
Subject: [PATCH] Replaced StaticAssert with the C++11 equivalent static_assert

---
 .../vtkPV3Foam/vtkOpenFOAMTupleRemap.H        | 14 +--
 .../vtkPVFoam/vtkOpenFOAMTupleRemap.H         | 12 ---
 .../Lists/DynamicList/DynamicList.H           |  9 +-
 .../containers/Lists/FixedList/FixedList.H    |  9 +-
 .../containers/Lists/PackedList/PackedList.H  |  8 +-
 src/OpenFOAM/containers/NamedEnum/NamedEnum.H |  4 +-
 src/OpenFOAM/db/error/StaticAssert.H          | 87 -------------------
 .../fields/Fields/DynamicField/DynamicField.H |  9 +-
 .../primitives/MatrixSpace/MatrixSpaceI.H     | 40 ++++++---
 .../primitives/VectorSpace/VectorSpaceI.H     |  8 +-
 .../functions/Polynomial/Polynomial.H         |  5 +-
 11 files changed, 65 insertions(+), 140 deletions(-)
 delete mode 100644 src/OpenFOAM/db/error/StaticAssert.H

diff --git a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkOpenFOAMTupleRemap.H b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkOpenFOAMTupleRemap.H
index 0a6680c93b..79f3ab3127 100644
--- a/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkOpenFOAMTupleRemap.H
+++ b/applications/utilities/postProcessing/graphics/PV3Readers/PV3FoamReader/vtkPV3Foam/vtkOpenFOAMTupleRemap.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -30,7 +30,6 @@ InClass
 #define vtkOpenFOAMTupleRemap_H
 
 // OpenFOAM includes
-#include "StaticAssert.H"
 #include "Swap.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -39,17 +38,6 @@ template<class Type>
 inline void vtkOpenFOAMTupleRemap(float vec[]);
 
 
-// a symmTensor specialization to remap OpenFOAM -> ParaView naming order
-// Qt/Core/pqScalarBarRepresentation.cxx defines this order
-//     { "XX", "YY", "ZZ", "XY", "YZ", "XZ" }
-// in pqScalarBarRepresentation::getDefaultComponentLabel()
-// whereas OpenFOAM uses this order
-//     { XX, XY, XZ, YY, YZ, ZZ }
-//
-// for extra safety, assert that symmTensor indeed has 6 components
-StaticAssert(Foam::symmTensor::nComponents == 6);
-
-
 // Template specialization for symmTensor
 template<>
 inline void vtkOpenFOAMTupleRemap<Foam::symmTensor>(float vec[])
diff --git a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMTupleRemap.H b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMTupleRemap.H
index 610eac4f34..d18bc79b33 100644
--- a/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMTupleRemap.H
+++ b/applications/utilities/postProcessing/graphics/PVReaders/PVFoamReader/vtkPVFoam/vtkOpenFOAMTupleRemap.H
@@ -30,7 +30,6 @@ InClass
 #define vtkOpenFOAMTupleRemap_H
 
 // OpenFOAM includes
-#include "StaticAssert.H"
 #include "Swap.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -39,17 +38,6 @@ template<class Type>
 inline void vtkOpenFOAMTupleRemap(float vec[]);
 
 
-// a symmTensor specialization to remap OpenFOAM -> ParaView naming order
-// Qt/Core/pqScalarBarRepresentation.cxx defines this order
-//     { "XX", "YY", "ZZ", "XY", "YZ", "XZ" }
-// in pqScalarBarRepresentation::getDefaultComponentLabel()
-// whereas OpenFOAM uses this order
-//     { XX, XY, XZ, YY, YZ, ZZ }
-//
-// for extra safety, assert that symmTensor indeed has 6 components
-StaticAssert(Foam::symmTensor::nComponents == 6);
-
-
 // Template specialization for symmTensor
 template<>
 inline void vtkOpenFOAMTupleRemap<Foam::symmTensor>(float vec[])
diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H
index f62ba3a41a..913e726f41 100644
--- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H
+++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H
@@ -44,7 +44,7 @@ SourceFiles
 #define DynamicList_H
 
 #include "List.H"
-#include "StaticAssert.H"
+#include <type_traits>
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -79,8 +79,11 @@ class DynamicList
 :
     public List<T>
 {
-    //- Avoid invalid sizing parameters
-    StaticAssert((SizeInc || SizeMult) && SizeDiv);
+    static_assert
+    (
+        (SizeInc || SizeMult) && SizeDiv,
+        "Invalid sizing parameters"
+    );
 
     // Private data
 
diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H
index c7974940c5..43d97eead2 100644
--- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H
+++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H
@@ -42,7 +42,7 @@ SourceFiles
 #include "uLabel.H"
 #include "Hash.H"
 #include "autoPtr.H"
-#include "StaticAssert.H"
+#include <type_traits>
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -70,8 +70,11 @@ template<class T> class SLList;
 template<class T, unsigned Size>
 class FixedList
 {
-    //- Size must be positive (non-zero) and also fit as a signed value
-    StaticAssert(Size && Size <= INT_MAX);
+    static_assert
+    (
+        Size && Size <= INT_MAX,
+        "Size must be positive (non-zero) and also fit as a signed value"
+    );
 
     // Private data
 
diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H
index 078a4dde9f..8af97000ff 100644
--- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H
+++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H
@@ -103,7 +103,7 @@ SourceFiles
 
 #include "labelList.H"
 #include "UIndirectList.H"
-#include "StaticAssert.H"
+#include <type_traits>
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -174,7 +174,11 @@ private:
     //  it is more efficient to use a normal list.
     //  Thus max nBits is 1/2 of the base storage size.
     //  For simplicity, assume 8-bit bytes in the assert.
-    StaticAssert(nBits && nBits <= (sizeof(StorageType) << 2));
+    static_assert
+    (
+        nBits && nBits <= (sizeof(StorageType) << 2),
+        "nBits must be positive (non-zero) and fit within the storage"
+    );
 
     // Private data
 
diff --git a/src/OpenFOAM/containers/NamedEnum/NamedEnum.H b/src/OpenFOAM/containers/NamedEnum/NamedEnum.H
index f4af06792c..32cb603022 100644
--- a/src/OpenFOAM/containers/NamedEnum/NamedEnum.H
+++ b/src/OpenFOAM/containers/NamedEnum/NamedEnum.H
@@ -36,9 +36,9 @@ SourceFiles
 #define NamedEnum_H
 
 #include "HashTable.H"
-#include "StaticAssert.H"
 #include "stringList.H"
 #include "wordList.H"
+#include <type_traits>
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -55,7 +55,7 @@ class NamedEnum
     public HashTable<int>
 {
     //- nEnum must be positive (non-zero)
-    StaticAssert(nEnum > 0);
+    static_assert(nEnum > 0, "nEnum must be positive (non-zero)");
 
     // Private Member Functions
 
diff --git a/src/OpenFOAM/db/error/StaticAssert.H b/src/OpenFOAM/db/error/StaticAssert.H
deleted file mode 100644
index 58fa86c170..0000000000
--- a/src/OpenFOAM/db/error/StaticAssert.H
+++ /dev/null
@@ -1,87 +0,0 @@
-/*---------------------------------------------------------------------------*\
-  =========                 |
-  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-   \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
-     \\/     M anipulation  |
--------------------------------------------------------------------------------
-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 <http://www.gnu.org/licenses/>.
-
-Class
-    Foam::StaticAssertionFailed
-
-Description
-    Macros and classes to provide static (compile-time) assertions.
-
-    Ideas from various sources
-    (http://www.ddj.com/cpp/184401547, http://www.boost.org)
-
-\*---------------------------------------------------------------------------*/
-
-#ifndef StaticAssert_H
-#define StaticAssert_H
-
-namespace Foam
-{
-
-//- Forward declaration of StaticAssertionFailed.
-//  Leave as an incomplete class so that sizeof(..) fails
-template<bool Truth> class StaticAssertionFailed;
-
-/*---------------------------------------------------------------------------*\
-                    Class StaticAssertionFailed Declaration
-\*---------------------------------------------------------------------------*/
-
-//- Specialization for successful assertions
-template<>
-class StaticAssertionFailed<true>
-{};
-
-
-//- Helper class for handling static assertions
-template<unsigned Test>
-class StaticAssertionTest {};
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-} // End namespace Foam
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-// Paste together strings, even if an argument is itself a macro
-#define StaticAssertMacro(X,Y)  StaticAssertMacro1(X,Y)
-#define StaticAssertMacro1(X,Y) StaticAssertMacro2(X,Y)
-#define StaticAssertMacro2(X,Y) X##Y
-
-#ifdef __GNUC__
-    #define StaticAssertUnusedTypedef __attribute__((unused))
-#else
-    #define StaticAssertUnusedTypedef
-#endif
-
-//- Assert that some test is true at compile-time
-#define StaticAssert(Test)                                                     \
-    typedef ::Foam::StaticAssertionTest                                        \
-    <                                                                          \
-        sizeof( ::Foam::StaticAssertionFailed<((Test) ? true : false)>)        \
-    > StaticAssertMacro(StaticAssertionTest, __LINE__) StaticAssertUnusedTypedef
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-#endif
-
-// ************************************************************************* //
diff --git a/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H b/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H
index 60cff25b94..e575ddf282 100644
--- a/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H
+++ b/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H
@@ -37,7 +37,7 @@ SourceFiles
 #define DynamicField_H
 
 #include "Field.H"
-#include "StaticAssert.H"
+#include <type_traits>
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -73,8 +73,11 @@ class DynamicField
 :
     public Field<T>
 {
-    //- Avoid invalid sizing parameters
-    StaticAssert((SizeInc || SizeMult) && SizeDiv);
+    static_assert
+    (
+        (SizeInc || SizeMult) && SizeDiv,
+        "Avoid invalid sizing parameters"
+    );
 
     // Private data
 
diff --git a/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H b/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H
index ff636aa933..207162b2c5 100644
--- a/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H
+++ b/src/OpenFOAM/primitives/MatrixSpace/MatrixSpaceI.H
@@ -23,7 +23,7 @@ License
 
 \*---------------------------------------------------------------------------*/
 
-#include "StaticAssert.H"
+#include <type_traits>
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
@@ -90,8 +90,16 @@ ConstBlock(const msType& matrix)
 :
     matrix_(matrix)
 {
-    StaticAssert(msType::mRows >= BRowStart + mRows);
-    StaticAssert(msType::nCols >= BColStart + nCols);
+    static_assert
+    (
+        msType::mRows >= BRowStart + mRows,
+        "Rows in block > rows in matrix"
+    );
+    static_assert
+    (
+        msType::nCols >= BColStart + nCols,
+        "Columns in block > columns in matrix"
+    );
 }
 
 
@@ -103,8 +111,16 @@ Block(msType& matrix)
 :
     matrix_(matrix)
 {
-    StaticAssert(msType::mRows >= BRowStart + mRows);
-    StaticAssert(msType::nCols >= BColStart + nCols);
+    static_assert
+    (
+        msType::mRows >= BRowStart + mRows,
+        "Rows in block > rows in matrix"
+    );
+    static_assert
+    (
+        msType::nCols >= BColStart + nCols,
+        "Columns in block > columns in matrix"
+    );
 }
 
 
@@ -114,7 +130,7 @@ template<class Form, class Cmpt, Foam::direction Mrows, Foam::direction Ncols>
 template<Foam::direction Row, Foam::direction Col>
 inline const Cmpt& Foam::MatrixSpace<Form, Cmpt, Mrows, Ncols>::elmt() const
 {
-    StaticAssert(Row < Mrows && Col < Ncols);
+    static_assert(Row < Mrows && Col < Ncols, "Address outside matrix");
     return this->v_[Row*Ncols + Col];
 }
 
@@ -123,7 +139,7 @@ template<class Form, class Cmpt, Foam::direction Mrows, Foam::direction Ncols>
 template<Foam::direction Row, Foam::direction Col>
 inline Cmpt& Foam::MatrixSpace<Form, Cmpt, Mrows, Ncols>::elmt()
 {
-    StaticAssert(Row < Mrows && Col < Ncols);
+    static_assert(Row < Mrows && Col < Ncols, "Address outside matrix");
     return this->v_[Row*Ncols + Col];
 }
 
@@ -256,7 +272,7 @@ template<class Form, class Cmpt, Foam::direction Mrows, Foam::direction Ncols>
 inline Foam::MatrixSpace<Form, Cmpt, Mrows, Ncols>
 Foam::MatrixSpace<Form, Cmpt, Mrows, Ncols>::identity()
 {
-    StaticAssert(Mrows == Ncols);
+    static_assert(Mrows == Ncols, "Matrix is not square");
     msType result(Zero);
 
     for (direction i=0; i<Ncols; ++i)
@@ -499,7 +515,7 @@ operator=
     const VectorSpace<VSForm, Cmpt, SubTensor::mRows>& v
 )
 {
-    StaticAssert(nCols == 1);
+    static_assert(nCols == 1, "Matrix must have a single column");
 
     for (direction i=0; i<SubTensor::mRows; ++i)
     {
@@ -560,7 +576,11 @@ inline typename typeOfInnerProduct<Cmpt, Form1, Form2>::type operator&
     const MatrixSpace<Form2, Cmpt, Mrows2, Ncols2>& matrix2
 )
 {
-    StaticAssert(Ncols1 == Mrows2);
+    static_assert
+    (
+        Ncols1 == Mrows2,
+        "Number of columns in matrix 1 != number of rows in matrix 2"
+    );
 
     typename typeOfInnerProduct<Cmpt, Form1, Form2>::type result(Zero);
 
diff --git a/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H b/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H
index 3b545a43e6..f90adbb0ff 100644
--- a/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H
+++ b/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H
@@ -27,7 +27,7 @@ License
 #include "products.H"
 #include "VectorSpaceOps.H"
 #include "ops.H"
-#include "StaticAssert.H"
+#include <type_traits>
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -79,7 +79,11 @@ VectorSpace<Form, Cmpt, Ncmpts>::ConstBlock<SubVector, BStart>::ConstBlock
 :
     vs_(vs)
 {
-    StaticAssert(vsType::nComponents >= BStart + nComponents);
+    static_assert
+    (
+        vsType::nComponents >= BStart + nComponents,
+        "Requested block size > VectorSpace size"
+    );
 }
 
 
diff --git a/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H b/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H
index b6f20330d8..2d8f11d3af 100644
--- a/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H
+++ b/src/OpenFOAM/primitives/functions/Polynomial/Polynomial.H
@@ -52,7 +52,7 @@ SourceFiles
 #include "scalar.H"
 #include "Ostream.H"
 #include "VectorSpace.H"
-#include "StaticAssert.H"
+#include <type_traits>
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -81,8 +81,7 @@ class Polynomial
 :
     public VectorSpace<Polynomial<PolySize>, scalar, PolySize>
 {
-    //- Size must be positive (non-zero)
-    StaticAssert(PolySize > 0);
+    static_assert(PolySize > 0, "Size must be positive (non-zero)");
 
     // Private data
 
-- 
GitLab