diff --git a/src/mesh/ItemValue.hpp b/src/mesh/ItemValue.hpp index 754f66ac7e450af35cf5d89e6c22b4f040c4a661..1b6e10e25e75e0566c3d93dd2a81f53d2c5a8939 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&