From b1cbee37fd5a40ab750856d20326eb4421f1bb3b Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Tue, 18 Dec 2018 17:02:48 +0100
Subject: [PATCH] Add some inline, constexpr and noexcept attributes

---
 src/mesh/ItemId.hpp              | 36 ++++++++++++++++++++++----------
 src/mesh/ItemValue.hpp           |  4 ++--
 src/mesh/MeshData.hpp            |  2 +-
 src/mesh/SubItemValuePerItem.hpp | 24 ++++++++++-----------
 src/utils/Array.hpp              |  8 +++----
 5 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/src/mesh/ItemId.hpp b/src/mesh/ItemId.hpp
index 11b87f708..8fc4161e4 100644
--- a/src/mesh/ItemId.hpp
+++ b/src/mesh/ItemId.hpp
@@ -1,6 +1,7 @@
 #ifndef ITEM_ID_HPP
 #define ITEM_ID_HPP
 
+#include <PastisMacros.hpp>
 #include <ItemType.hpp>
 
 template <ItemType item_type>
@@ -13,39 +14,53 @@ class ItemIdT
   base_type m_id;
 
  public:
-  operator const base_type&() const
+  PASTIS_INLINE
+  constexpr operator const base_type&() const
   {
     return m_id;
   }
 
-  ItemIdT operator++(int)
+  PASTIS_INLINE
+  constexpr ItemIdT operator++(int)
   {
     ItemIdT item_id(m_id);
     ++m_id;
     return std::move(item_id);
   }
 
-  ItemIdT& operator++()
+  PASTIS_INLINE
+  constexpr ItemIdT& operator++()
   {
     ++m_id;
     return *this;
   }
 
-  ItemIdT& operator=(const base_type& id)
+  PASTIS_INLINE
+  constexpr ItemIdT& operator=(const base_type& id)
   {
     m_id = id;
     return *this;
   }
 
-  ItemIdT& operator=(const ItemIdT&) = default;
-  ItemIdT& operator=(ItemIdT&&) = default;
+  PASTIS_INLINE
+  constexpr ItemIdT& operator=(const ItemIdT&) = default;
 
-  ItemIdT(const base_type& id) : m_id{id}{}
+  PASTIS_INLINE
+  constexpr ItemIdT& operator=(ItemIdT&&) = default;
 
-  ItemIdT(const ItemIdT&) = default;
+  PASTIS_INLINE
+  constexpr ItemIdT(const base_type& id) : m_id{id}{}
 
-  ItemIdT(ItemIdT&&) = default;
-  ItemIdT() = default;
+  PASTIS_INLINE
+  constexpr ItemIdT(const ItemIdT&) = default;
+
+  PASTIS_INLINE
+  constexpr ItemIdT(ItemIdT&&) = default;
+
+  PASTIS_INLINE
+  constexpr ItemIdT() = default;
+
+  PASTIS_INLINE
   ~ItemIdT() = default;
 
   // forbidden rules
@@ -70,7 +85,6 @@ class ItemIdT
     static_assert(other_item_type == item_type,
                   "wrong type of item");
   }
-
 };
 
 using NodeId = ItemIdT<ItemType::node>;
diff --git a/src/mesh/ItemValue.hpp b/src/mesh/ItemValue.hpp
index 754f66ac7..bfea6dd3d 100644
--- a/src/mesh/ItemValue.hpp
+++ b/src/mesh/ItemValue.hpp
@@ -47,14 +47,14 @@ class ItemValue
   // Following Kokkos logic, these classes are view and const view does allow
   // changes in data
   PASTIS_FORCEINLINE
-  DataType& operator[](const ItemId& i) const
+  DataType& operator[](const ItemId& i) const noexcept(NO_ASSERT)
   {
     Assert(m_is_built);
     return m_values[i];
   }
 
   template <typename IndexType>
-  DataType& operator[](const IndexType& i) const
+  DataType& operator[](const IndexType& i) const noexcept(NO_ASSERT)
   {
     static_assert(std::is_same<IndexType,ItemId>(),
                   "ItemValue must be indexed by ItemId");
diff --git a/src/mesh/MeshData.hpp b/src/mesh/MeshData.hpp
index 6bd7e8925..f9a2aeb57 100644
--- a/src/mesh/MeshData.hpp
+++ b/src/mesh/MeshData.hpp
@@ -179,7 +179,7 @@ class MeshData
               const auto& face_nodes = face_to_node_matrix[l];
 
 #warning should this lambda be replaced by a precomputed correspondance?
-              std::function local_node_number_in_cell
+              auto local_node_number_in_cell
                   = [&](const NodeId& node_number) {
                       for (size_t i_node=0; i_node<cell_nodes.size(); ++i_node) {
                         if (node_number == cell_nodes[i_node]) {
diff --git a/src/mesh/SubItemValuePerItem.hpp b/src/mesh/SubItemValuePerItem.hpp
index afe1ee4fa..edb73dd5c 100644
--- a/src/mesh/SubItemValuePerItem.hpp
+++ b/src/mesh/SubItemValuePerItem.hpp
@@ -58,14 +58,14 @@ class SubItemValuePerItem<DataType,
 
    public:
     PASTIS_INLINE
-    const DataType& operator[](const size_t& i) const
+    const DataType& operator[](const size_t& i) const noexcept(NO_ASSERT)
     {
       Assert(i<m_size);
       return m_sub_values[i];
     }
 
     PASTIS_FORCEINLINE
-    DataType& operator[](const size_t& i)
+    DataType& operator[](const size_t& i) noexcept(NO_ASSERT)
     {
       Assert(i<m_size);
       return m_sub_values[i];
@@ -85,7 +85,7 @@ class SubItemValuePerItem<DataType,
     PASTIS_INLINE
     SubView(const Array<DataType>& values,
             const size_t& begin,
-            const size_t& end)
+            const size_t& end) noexcept(NO_ASSERT)
         : m_sub_values(&(values[begin])),
           m_size(end-begin)
     {
@@ -103,7 +103,7 @@ class SubItemValuePerItem<DataType,
   // Following Kokkos logic, these classes are view and const view does allow
   // changes in data
   PASTIS_FORCEINLINE
-  DataType& operator()(const ItemId& j, const size_t& r) const
+  DataType& operator()(const ItemId& j, const size_t& r) const noexcept(NO_ASSERT)
   {
     Assert(m_is_built);
     return m_values[m_host_row_map(size_t{j})+r];
@@ -111,7 +111,7 @@ class SubItemValuePerItem<DataType,
 
   template <typename IndexType>
   PASTIS_FORCEINLINE
-  DataType& operator()(const IndexType& j, const size_t& r) const
+  DataType& operator()(const IndexType& j, const size_t& r) const noexcept(NO_ASSERT)
   {
     static_assert(std::is_same<IndexType, size_t>(),
                   "SubItemValuePerItem indexed by ItemId");
@@ -119,7 +119,7 @@ class SubItemValuePerItem<DataType,
   }
 
   PASTIS_INLINE
-  size_t numberOfValues() const
+  size_t numberOfValues() const noexcept(NO_ASSERT)
   {
     Assert(m_is_built);
     return m_values.size();
@@ -128,14 +128,14 @@ class SubItemValuePerItem<DataType,
   // Following Kokkos logic, these classes are view and const view does allow
   // changes in data
   PASTIS_FORCEINLINE
-  DataType& operator[](const size_t& i) const
+  DataType& operator[](const size_t& i) const noexcept(NO_ASSERT)
   {
     Assert(m_is_built);
     return m_values[i];
   }
 
   template <typename IndexType>
-  DataType& operator[](const IndexType& i) const
+  DataType& operator[](const IndexType& i) const noexcept(NO_ASSERT)
   {
     static_assert(std::is_same<IndexType, size_t>(),
                   "Access to SubItemValuePerItem's array must be indexed by size_t");
@@ -143,7 +143,7 @@ class SubItemValuePerItem<DataType,
   }
 
   PASTIS_INLINE
-  size_t numberOfItems() const
+  size_t numberOfItems() const noexcept(NO_ASSERT)
   {
     Assert(m_is_built);
     Assert(m_host_row_map.extent(0) != 0);
@@ -151,14 +151,14 @@ class SubItemValuePerItem<DataType,
   }
 
   PASTIS_INLINE
-  size_t numberOfSubValues(const size_t& i_cell) const
+  size_t numberOfSubValues(const size_t& i_cell) const noexcept(NO_ASSERT)
   {
     Assert(m_is_built);
     return m_host_row_map(i_cell+1)-m_host_row_map(i_cell);
   }
 
   PASTIS_INLINE
-  SubView itemValues(const size_t& i_cell)
+  SubView itemValues(const size_t& i_cell) noexcept(NO_ASSERT)
   {
     Assert(m_is_built);
     const auto& cell_begin = m_host_row_map(i_cell);
@@ -169,7 +169,7 @@ class SubItemValuePerItem<DataType,
   // Following Kokkos logic, these classes are view and const view does allow
   // changes in data
   PASTIS_INLINE
-  SubView itemValues(const size_t& i_cell) const
+  SubView itemValues(const size_t& i_cell) const noexcept(NO_ASSERT)
   {
     Assert(m_is_built);
     const auto& cell_begin = m_host_row_map(i_cell);
diff --git a/src/utils/Array.hpp b/src/utils/Array.hpp
index e7273ecee..33d8ba7ac 100644
--- a/src/utils/Array.hpp
+++ b/src/utils/Array.hpp
@@ -21,13 +21,13 @@ class Array
 
  public:
   PASTIS_INLINE
-  size_t size() const
+  size_t size() const noexcept
   {
     return m_values.extent(0);
   }
 
   PASTIS_INLINE
-  DataType& operator[](const index_type& i) const
+  DataType& operator[](const index_type& i) const noexcept(NO_ASSERT)
   {
     Assert(i<m_values.extent(0));
     return m_values[i];
@@ -43,7 +43,7 @@ class Array
 
   template <typename DataType2>
   PASTIS_INLINE
-  Array& operator=(const Array<DataType2>& array)
+  Array& operator=(const Array<DataType2>& array) noexcept
   {
     // ensures that DataType is the same as source DataType2
     static_assert(std::is_same<std::remove_const_t<DataType>, std::remove_const_t<DataType2>>(),
@@ -67,7 +67,7 @@ class Array
 
   template <typename DataType2>
   PASTIS_INLINE
-  Array(const Array<DataType2>& array)
+  Array(const Array<DataType2>& array) noexcept
   {
     this->operator=(array);
   }
-- 
GitLab