diff --git a/src/TNL/Containers/Algorithms/ArrayAssignment.h b/src/TNL/Containers/Algorithms/ArrayAssignment.h index 170d3e2539f38c63d13c24182ccd4b8eaeef8dd4..0d3a9b145a75936e58b0a31b584f8ca6dacd3d08 100644 --- a/src/TNL/Containers/Algorithms/ArrayAssignment.h +++ b/src/TNL/Containers/Algorithms/ArrayAssignment.h @@ -50,17 +50,13 @@ template< typename Array, typename T > struct ArrayAssignment< Array, T, true > { - static void resize( Array& a, const T& t ) - { - a.setSize( t.getSize() ); - } - static void assign( Array& a, const T& t ) { - TNL_ASSERT_EQ( a.getSize(), t.getSize(), "The sizes of the arrays must be equal." ); - ArrayOperations< typename Array::DeviceType, typename T::DeviceType >::template - copyMemory< typename Array::ValueType, typename T::ValueType, typename Array::IndexType > - ( a.getArrayData(), t.getArrayData(), t.getSize() ); + a.setSize( t.getSize() ); + if( t.getSize() > 0 ) // we allow even assignment of empty arrays + ArrayOperations< typename Array::DeviceType, typename T::DeviceType >::template + copyMemory< typename Array::ValueType, typename T::ValueType, typename Array::IndexType > + ( a.getArrayData(), t.getArrayData(), t.getSize() ); }; }; @@ -72,9 +68,6 @@ template< typename Array, typename T > struct ArrayAssignment< Array, T, false > { - static void resize( Array& a, const T& t ) - { - }; static void assign( Array& a, const T& t ) { TNL_ASSERT_FALSE( a.empty(), "Cannot assign value to empty array." ); diff --git a/src/TNL/Containers/Array.hpp b/src/TNL/Containers/Array.hpp index a3107fbc42fcbe57330d8511621b82ecd0f008f0..61c4db1da44d67ae6380eadcd9dedf8e11e6eee5 100644 --- a/src/TNL/Containers/Array.hpp +++ b/src/TNL/Containers/Array.hpp @@ -549,7 +549,6 @@ Array< Value, Device, Index >& Array< Value, Device, Index >:: operator=( const T& data ) { - Algorithms::ArrayAssignment< Array, T >::resize( *this, data ); Algorithms::ArrayAssignment< Array, T >::assign( *this, data ); return *this; }