From 72392790d4a55d4d8c47c0eb7abf505cd0e9e445 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com>
Date: Wed, 2 Mar 2022 17:13:16 +0100
Subject: [PATCH] Simplify slightly implementation

---
 src/mesh/ItemArray.hpp | 19 +++++--------------
 src/mesh/ItemValue.hpp | 18 +++++-------------
 2 files changed, 10 insertions(+), 27 deletions(-)

diff --git a/src/mesh/ItemArray.hpp b/src/mesh/ItemArray.hpp
index 9213bd313..90ba27629 100644
--- a/src/mesh/ItemArray.hpp
+++ b/src/mesh/ItemArray.hpp
@@ -92,22 +92,13 @@ class ItemArray
     m_values.fill(data);
   }
 
-  // Following Kokkos logic, these classes are view and const view does allow
-  // changes in data
-  PUGS_FORCEINLINE
-  Array<DataType>
-  operator[](const ItemId& i) const noexcept(NO_ASSERT)
+  template <ItemType item_t>
+  PUGS_INLINE Array<DataType>
+  operator[](const ItemIdT<item_t>& item_id) const noexcept(NO_ASSERT)
   {
+    static_assert(item_t == item_type, "invalid ItemId type");
     Assert(this->isBuilt());
-    Assert(i < this->numberOfItems());
-    return m_values[i];
-  }
-
-  template <typename IndexType>
-  Array<DataType>
-  operator[](const IndexType&) const noexcept(NO_ASSERT)
-  {
-    static_assert(std::is_same_v<IndexType, ItemId>, "ItemArray must be indexed by ItemId");
+    return m_values[item_id];
   }
 
   PUGS_INLINE
diff --git a/src/mesh/ItemValue.hpp b/src/mesh/ItemValue.hpp
index e6df4b705..af45137f5 100644
--- a/src/mesh/ItemValue.hpp
+++ b/src/mesh/ItemValue.hpp
@@ -100,21 +100,13 @@ class ItemValue
     m_values.fill(data);
   }
 
-  // Following Kokkos logic, these classes are view and const view does allow
-  // changes in data
-  PUGS_FORCEINLINE
-  DataType&
-  operator[](const ItemId& i) const noexcept(NO_ASSERT)
+  template <ItemType item_t>
+  PUGS_INLINE DataType&
+  operator[](const ItemIdT<item_t>& item_id) const noexcept(NO_ASSERT)
   {
+    static_assert(item_t == item_type, "invalid ItemId type");
     Assert(this->isBuilt());
-    return m_values[i];
-  }
-
-  template <typename IndexType>
-  DataType&
-  operator[](const IndexType&) const noexcept(NO_ASSERT)
-  {
-    static_assert(std::is_same_v<IndexType, ItemId>, "ItemValue must be indexed by ItemId");
+    return m_values[item_id];
   }
 
   template <typename DataType2, typename ConnectivityPtr2>
-- 
GitLab