From 841a1420201b46c8cb564c33ef3414a522334b7a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com>
Date: Mon, 27 Sep 2021 12:01:16 +0200
Subject: [PATCH] Add an external size function for convenience

---
 src/mesh/ItemValue.hpp   | 7 +++++++
 src/utils/Array.hpp      | 7 +++++++
 src/utils/SmallArray.hpp | 7 +++++++
 3 files changed, 21 insertions(+)

diff --git a/src/mesh/ItemValue.hpp b/src/mesh/ItemValue.hpp
index ebc5f4051..d48468f39 100644
--- a/src/mesh/ItemValue.hpp
+++ b/src/mesh/ItemValue.hpp
@@ -175,6 +175,13 @@ class ItemValue
   ~ItemValue() = default;
 };
 
+template <typename DataType, ItemType item_type, typename ConnectivityPtr>
+PUGS_INLINE size_t
+size(const ItemValue<DataType, item_type, ConnectivityPtr>& item_value)
+{
+  return item_value.numberOfItems();
+}
+
 template <typename DataType>
 using NodeValue = ItemValue<DataType, ItemType::node>;
 
diff --git a/src/utils/Array.hpp b/src/utils/Array.hpp
index 54786db88..f459821bb 100644
--- a/src/utils/Array.hpp
+++ b/src/utils/Array.hpp
@@ -140,6 +140,13 @@ class [[nodiscard]] Array
   ~Array() = default;
 };
 
+template <typename DataType>
+PUGS_INLINE size_t
+size(const Array<DataType>& array)
+{
+  return array.size();
+}
+
 template <typename DataType, typename... RT>
 PUGS_INLINE Array<DataType>
 encapsulate(const Kokkos::View<DataType*, RT...>& values)
diff --git a/src/utils/SmallArray.hpp b/src/utils/SmallArray.hpp
index b5186a7f6..336e6e6ff 100644
--- a/src/utils/SmallArray.hpp
+++ b/src/utils/SmallArray.hpp
@@ -128,6 +128,13 @@ class [[nodiscard]] SmallArray
   ~SmallArray() = default;
 };
 
+template <typename DataType>
+PUGS_INLINE size_t
+size(const SmallArray<DataType>& array)
+{
+  return array.size();
+}
+
 // map, multimap, unordered_map and stack cannot be copied this way
 template <typename Container>
 PUGS_INLINE SmallArray<std::remove_const_t<typename Container::value_type>>
-- 
GitLab