Skip to content
Snippets Groups Projects
Commit ac58a1af authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add affectation by an Array

Check ItemValue is initialized and that the Array has the correct size
parent 1475f720
No related branches found
No related tags found
1 merge request!11Feature/mpi
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define ITEM_VALUE_HPP #define ITEM_VALUE_HPP
#include <PastisAssert.hpp> #include <PastisAssert.hpp>
#include <PastisOStream.hpp>
#include <Array.hpp> #include <Array.hpp>
...@@ -68,6 +69,34 @@ class ItemValue ...@@ -68,6 +69,34 @@ class ItemValue
return m_values.size(); 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> template <typename DataType2>
PASTIS_INLINE PASTIS_INLINE
ItemValue& ItemValue&
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment