From f9819c66459e9aededd805c075f1b37da73bac6f Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 29 Jul 2012 20:02:25 +0000 Subject: [PATCH] (svn r24448) -Fix [FS#5255]: Copy constructor and assignment operator cannot be implicit template specialisations. (adf88) --- src/core/smallvec_type.hpp | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/core/smallvec_type.hpp b/src/core/smallvec_type.hpp index d70505e8c9..ccf8dbaece 100644 --- a/src/core/smallvec_type.hpp +++ b/src/core/smallvec_type.hpp @@ -39,21 +39,39 @@ public: * Copy constructor. * @param other The other vector to copy. */ + SmallVector(const SmallVector &other) : data(NULL), items(0), capacity(0) + { + this->Assign(other); + } + + /** + * Generic copy constructor. + * @param other The other vector to copy. + */ template SmallVector(const SmallVector &other) : data(NULL), items(0), capacity(0) { - MemCpyT(this->Append(other.Length()), other.Begin(), other.Length()); + this->Assign(other); } /** * Assignment. - * @param other The new vector that. + * @param other The other vector to assign. + */ + SmallVector &operator=(const SmallVector &other) + { + this->Assign(other); + return *this; + } + + /** + * Generic assignment. + * @param other The other vector to assign. */ template SmallVector &operator=(const SmallVector &other) { - this->Reset(); - MemCpyT(this->Append(other.Length()), other.Begin(), other.Length()); + this->Assign(other); return *this; } @@ -62,6 +80,18 @@ public: free(this->data); } + /** + * Assign items from other vector. + */ + template + inline void Assign(const SmallVector &other) + { + if ((const void *)&other == (void *)this) return; + + this->Clear(); + if (other.Length() > 0) MemCpyT(this->Append(other.Length()), other.Begin(), other.Length()); + } + /** * Remove all items from the list. */