1 #ifndef CORE_ValArray_H
2 #define CORE_ValArray_H
4 #include "CORE_Array.h"
8 #include "functions_numeric.h"
69 template <
typename T,
class I>
75 std::valarray<T> mValues;
128 mem+=mValues.size()*
sizeof(T);
142 if (n!=mValues.size()) mValues.resize(n);
148 return mValues.size();
154 std::valarray<T> newValues(n);
156 tIndex p=functions_numeric::min(n,this->
getSize());
157 Copy(p,mValues,newValues);
158 mValues.swap(newValues);
170 if (i>=mValues.size()) {
173 "CORE_ValArray["+std::to_string(i)+
"] is out of bounds [0,"+std::to_string(mValues.size())+
"[ for reading");
183 if (i>=mValues.size()) {
186 "CORE_ValArray["+std::to_string(i)+
"] is out of bounds [0,"+std::to_string(mValues.size())+
"[ for writing ");
200 return std::cbegin(this->mValues);
205 inline constexpr
auto cend()
const {
206 return std::cend(this->mValues);
212 return std::begin(this->mValues);
218 return std::end(this->mValues);
226 return rbegin(this->mValues);
233 return rend(this->mValues);
246 inline constexpr
auto crend()
const {
248 return crend(this->mValues);
313 inline void swap(
const tIndex& i,
const tIndex& j) {
314 std::swap(mValues[i],mValues[j]);
this class describes an array of values T of dynamical size with algebrical operators and I is an imp...
Definition: CORE_Array.h:91
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:17
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
this class describes an arithmetic array type implemented with a std::valarray object with implementa...
Definition: CORE_ValArray.h:70
constexpr auto cend() const
return end iterator for reading
Definition: CORE_ValArray.h:205
CORE_ValArray(const tIndex &n)
build an array of size n
Definition: CORE_ValArray.h:87
constexpr auto cbegin() const
return begin iterator for reading
Definition: CORE_ValArray.h:199
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: CORE_ValArray.h:126
T & operator[](const tIndex &i)
get the i-th element for writting. Do not verify the bounds
Definition: CORE_ValArray.h:181
constexpr auto crbegin() const
return reverse begin iterator for reading
Definition: CORE_ValArray.h:239
tIndex getSize() const
return the size of the array for writing
Definition: CORE_ValArray.h:147
auto rbegin()
return reverse begin iterator for writing
Definition: CORE_ValArray.h:224
const std::valarray< T > & getArray() const
get the array for reading
Definition: CORE_ValArray.h:263
auto rend()
return reverse end iterator for writing
Definition: CORE_ValArray.h:231
auto end()
return end iterator for writing
Definition: CORE_ValArray.h:217
constexpr auto crend() const
return reverse end iterator for reading
Definition: CORE_ValArray.h:246
void resize(const tIndex &n)
modify the size of the array and keep its old values
Definition: CORE_ValArray.h:153
void swap(const tIndex &i, const tIndex &j)
swap the 2 elements of the array
Definition: CORE_ValArray.h:313
auto begin()
return begin iterator for writing
Definition: CORE_ValArray.h:211
const T & operator[](const tIndex &i) const
get the i-th element for reading. Do not verify the bounds
Definition: CORE_ValArray.h:168
std::valarray< T > & getArray()
get the array
Definition: CORE_ValArray.h:257
void setSize(const tIndex &n)
set the number of values
Definition: CORE_ValArray.h:140
const T * getValues() const
get the values of the array for reading
Definition: CORE_ValArray.h:270
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: CORE_ValArray.h:114
virtual ~CORE_ValArray()
destroy an instance of this
Definition: CORE_ValArray.h:95
void swap(CORE_ValArray< T, I > &a)
swap the contents of the array
Definition: CORE_ValArray.h:306
T * getValues()
get the values of the array
Definition: CORE_ValArray.h:276
CORE_ValArray()
build an array of T*
Definition: CORE_ValArray.h:81