From d6c5d2299e3a2baff434cf08c4271c3b7c3cd686 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Oberhuber?= <oberhuber.tomas@gmail.com>
Date: Wed, 10 Apr 2019 20:47:17 +0200
Subject: [PATCH] Fixed array assignement.

---
 src/TNL/Containers/Algorithms/ArrayAssignment.h | 17 +++++------------
 src/TNL/Containers/Array.hpp                    |  1 -
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/src/TNL/Containers/Algorithms/ArrayAssignment.h b/src/TNL/Containers/Algorithms/ArrayAssignment.h
index 170d3e2539..0d3a9b145a 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 a3107fbc42..61c4db1da4 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;
 }
-- 
GitLab