From ac58a1af0739866d52f8a23e19d9b145d9aaf981 Mon Sep 17 00:00:00 2001
From: Stephane Del Pino <stephane.delpino44@gmail.com>
Date: Fri, 28 Sep 2018 18:11:12 +0200
Subject: [PATCH] Add affectation by an Array

Check ItemValue is initialized and that the Array has the correct size
---
 src/mesh/ItemValue.hpp | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/src/mesh/ItemValue.hpp b/src/mesh/ItemValue.hpp
index 754f66ac7..1b6e10e25 100644
--- a/src/mesh/ItemValue.hpp
+++ b/src/mesh/ItemValue.hpp
@@ -2,6 +2,7 @@
 #define ITEM_VALUE_HPP
 
 #include <PastisAssert.hpp>
+#include <PastisOStream.hpp>
 
 #include <Array.hpp>
 
@@ -68,6 +69,34 @@ class ItemValue
     return m_values.size();
   }
 
+  template <typename DataType2>
+  PASTIS_INLINE
+  ItemValue&
+  operator=(const Array<DataType2>& values)
+  {
+    // ensures that DataType is the same as source DataType2
+    static_assert(std::is_same<std::remove_const_t<DataType>, std::remove_const_t<DataType2>>(),
+                  "Cannot assign ItemValue of different type");
+    // ensures that const is not lost through copy
+    static_assert(((std::is_const<DataType2>() and std::is_const<DataType>())
+                   or not std::is_const<DataType2>()),
+                  "Cannot assign  ItemValue of const to ItemValue of non-const");
+
+    if (not m_is_built) {
+      perr() << "Cannot assign array of values to a non-built ItemValue\n";
+      std::exit(1);
+    }
+    if (m_values.size() != values.size()) {
+      perr() << "Cannot assign an array of values of a different size\n";
+      std::exit(1);
+    }
+
+    m_values = values;
+
+    return *this;
+
+  }
+
   template <typename DataType2>
   PASTIS_INLINE
   ItemValue&
-- 
GitLab