From e62555370e6f14a78217cdd7e87c9f3b3d315f95 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Thu, 30 Aug 2018 20:55:08 +0200 Subject: Vector: Copy arrays in a sane way for non-trivially copyable types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoids this type of compilation warnings: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of non-trivially copyable type ‘class Complex’; use copy-assignment or copy-initialization instead [-Werror=class-memaccess] Change-Id: I9724454dfb7b87f74f39074e4004580ac3b5fe5c --- CommonLibs/Vector.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'CommonLibs') diff --git a/CommonLibs/Vector.h b/CommonLibs/Vector.h index 51a9fb1..9119683 100644 --- a/CommonLibs/Vector.h +++ b/CommonLibs/Vector.h @@ -204,10 +204,15 @@ template class Vector { */ void copyToSegment(Vector& other, size_t start, size_t span) const { - T* base = other.mStart + start; - assert(base+span<=other.mEnd); + unsigned int i; + T* dst = other.mStart + start; + T* src = mStart; + assert(dst+span<=other.mEnd); assert(mStart+span<=mEnd); - memcpy(base,mStart,span*sizeof(T)); + for (i = 0; i < span; i++, src++, dst++) + *dst = *src; + /*TODO if not non-trivially copyable type class, optimize: + memcpy(dst,mStart,span*sizeof(T)); */ } /** Copy all of this Vector to a segment of another Vector. */ -- cgit v1.2.3