From 1a0c91f6a508ae03089d6b9395492819325e9f8e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com>
Date: Thu, 8 Apr 2021 19:04:01 +0200
Subject: [PATCH] Get ride of SubItemValuePerItem::SubView

Now returns a subArray. This simplifies the code, makes it safer and
more consistent without any performances loss.
---
 src/mesh/SubItemValuePerItem.hpp | 65 ++++++--------------------------
 1 file changed, 12 insertions(+), 53 deletions(-)

diff --git a/src/mesh/SubItemValuePerItem.hpp b/src/mesh/SubItemValuePerItem.hpp
index 63bff8a35..b86b075ec 100644
--- a/src/mesh/SubItemValuePerItem.hpp
+++ b/src/mesh/SubItemValuePerItem.hpp
@@ -50,55 +50,6 @@ class SubItemValuePerItem
  public:
   using ToShared = SubItemValuePerItem<DataType, ItemOfItem, ConnectivitySharedPtr>;
 
-  class SubView
-  {
-   public:
-    using data_type = DataType;
-
-   private:
-    PUGS_RESTRICT DataType* const m_sub_values;
-    const size_t m_size;
-
-   public:
-    template <typename IndexType>
-    PUGS_FORCEINLINE DataType&
-    operator[](IndexType i) const noexcept(NO_ASSERT)
-    {
-      static_assert(std::is_integral_v<IndexType>, "SubView is indexed by integral values");
-      Assert(i < m_size);
-      return m_sub_values[i];
-    }
-
-    template <typename IndexType>
-    PUGS_FORCEINLINE DataType&
-    operator[](IndexType i) noexcept(NO_ASSERT)
-    {
-      static_assert(std::is_integral_v<IndexType>, "SubView is indexed by integral values");
-      Assert(i < m_size);
-      return m_sub_values[i];
-    }
-
-    PUGS_INLINE
-    size_t
-    size() const noexcept
-    {
-      return m_size;
-    }
-
-    SubView(const SubView&)     = delete;
-    SubView(SubView&&) noexcept = delete;
-
-    PUGS_INLINE
-    SubView(const Array<DataType>& values, size_t begin, size_t end) noexcept(NO_ASSERT)
-      : m_sub_values(&(values[begin])), m_size(end - begin)
-    {
-      Assert(begin <= end);
-      Assert(end <= values.size());
-    }
-
-    ~SubView() = default;
-  };
-
   friend PUGS_INLINE SubItemValuePerItem<std::remove_const_t<DataType>, ItemOfItem, ConnectivityPtr>
   copy(SubItemValuePerItem<DataType, ItemOfItem, ConnectivityPtr>& source)
   {
@@ -178,8 +129,16 @@ class SubItemValuePerItem
     return m_host_row_map(size_t{item_id} + 1) - m_host_row_map(size_t{item_id});
   }
 
+  PUGS_INLINE
+  void
+  fill(const DataType& data) const noexcept
+  {
+    static_assert(not std::is_const_v<DataType>, "Cannot modify ItemValue of const");
+    m_values.fill(data);
+  }
+
   template <typename IndexType>
-  PUGS_INLINE SubView
+  PUGS_INLINE Array<DataType>
   itemValues(IndexType item_id) noexcept(NO_ASSERT)
   {
     static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
@@ -187,13 +146,13 @@ class SubItemValuePerItem
     Assert(item_id < this->numberOfItems());
     const auto& item_begin = m_host_row_map(size_t{item_id});
     const auto& item_end   = m_host_row_map(size_t{item_id} + 1);
-    return SubView(m_values, item_begin, item_end);
+    return subArray(m_values, item_begin, item_end - item_begin);
   }
 
   // Following Kokkos logic, these classes are view and const view does allow
   // changes in data
   template <typename IndexType>
-  PUGS_INLINE SubView
+  PUGS_INLINE Array<DataType>
   itemValues(IndexType item_id) const noexcept(NO_ASSERT)
   {
     static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
@@ -201,7 +160,7 @@ class SubItemValuePerItem
     Assert(item_id < this->numberOfItems());
     const auto& item_begin = m_host_row_map(size_t{item_id});
     const auto& item_end   = m_host_row_map(size_t{item_id} + 1);
-    return SubView(m_values, item_begin, item_end);
+    return subArray(m_values, item_begin, item_end - item_begin);
   }
 
   template <typename DataType2, typename ConnectivityPtr2>
-- 
GitLab