Skip to content

Commit 11e39d2

Browse files
authored
added equal assignment operator Array<T>::operator=(ArrayView<T const> &) (#266)
* added equal assignment operator Array<T>::operator=(ArrayView<T const> &)
1 parent 7860522 commit 11e39d2

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/Array.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,28 @@ class Array : public ArrayView< T,
184184
return *this;
185185
}
186186

187+
/**
188+
* @brief Copy assignment operator, performs a deep copy of rhs.
189+
* @param rhs Source for the assignment.
190+
* @return *this.
191+
*/
192+
LVARRAY_HOST_DEVICE
193+
Array & operator=( typename ParentClass::ViewTypeConst const & rhs )
194+
{
195+
bufferManipulation::copyInto( this->m_dataBuffer, this->size(), rhs.dataBuffer(), rhs.size() );
196+
197+
INDEX_TYPE const * const dims = rhs.dims();
198+
INDEX_TYPE const * const strides = rhs.strides();
199+
for( int i = 0; i < NDIM; ++i )
200+
{
201+
this->m_dims[ i ] = dims[ i ];
202+
this->m_strides[ i ] = strides[ i ];
203+
}
204+
205+
setSingleParameterResizeIndex( rhs.getSingleParameterResizeIndex() );
206+
return *this;
207+
}
208+
187209
/**
188210
* @brief Move assignment operator, performs a shallow copy of rhs.
189211
* @param rhs Source for the assignment.

src/ArrayView.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class ArrayView
8585
/// The integer type used for indexing.
8686
using IndexType = INDEX_TYPE;
8787

88+
/// The type when the data type is const.
89+
using ViewTypeConst = ArrayView< std::remove_const_t< T > const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE >;
90+
91+
8892
/// The type when all inner array classes are converted to const views.
8993
using NestedViewType = ArrayView< std::remove_reference_t< typeManipulation::NestedViewType< T > >,
9094
NDIM, USD, INDEX_TYPE, BUFFER_TYPE >;
@@ -274,12 +278,12 @@ class ArrayView
274278
* @return Return a new ArrayView where @c T is @c const.
275279
*/
276280
inline LVARRAY_HOST_DEVICE constexpr
277-
ArrayView< T const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE > toViewConst() const &
281+
ViewTypeConst toViewConst() const &
278282
{
279-
return ArrayView< T const, NDIM, USD, INDEX_TYPE, BUFFER_TYPE >( m_dims,
280-
m_strides,
281-
m_singleParameterResizeIndex,
282-
m_dataBuffer );
283+
return ViewTypeConst( m_dims,
284+
m_strides,
285+
m_singleParameterResizeIndex,
286+
m_dataBuffer );
283287
}
284288

285289
/**

0 commit comments

Comments
 (0)