From a168d2af4ec3128d145ccd6f2d714f890a29f270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 28 Aug 2013 16:31:11 +0200 Subject: [PATCH] Proper noexcept move constructor for Mesh. Also documented the inability to copy. --- src/Mesh.cpp | 32 ++++++++++++++------------------ src/Mesh.h | 13 ++++++++----- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 7b770eadb..4f8d8d963 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -75,7 +75,7 @@ Mesh::~Mesh() { (this->*destroyImplementation)(); } -Mesh::Mesh(Mesh&& other): _id(other._id), _primitive(other._primitive), _vertexCount(other._vertexCount), _indexCount(other._indexCount) +Mesh::Mesh(Mesh&& other) noexcept: _id(other._id), _primitive(other._primitive), _vertexCount(other._vertexCount), _indexCount(other._indexCount) #ifndef MAGNUM_TARGET_GLES2 , _indexStart(other._indexStart), _indexEnd(other._indexEnd) #endif @@ -90,30 +90,26 @@ Mesh::Mesh(Mesh&& other): _id(other._id), _primitive(other._primitive), _vertexC other._id = 0; } -Mesh& Mesh::operator=(Mesh&& other) { - (this->*destroyImplementation)(); - - _id = other._id; - _primitive = other._primitive; - _vertexCount = other._vertexCount; - _indexCount = other._indexCount; +Mesh& Mesh::operator=(Mesh&& other) noexcept { + std::swap(_id, other._id); + std::swap(_primitive, other._primitive); + std::swap(_vertexCount, other._vertexCount); + std::swap(_indexCount, other._indexCount); #ifndef MAGNUM_TARGET_GLES2 - _indexStart = other._indexStart; - _indexEnd = other._indexEnd; + std::swap(_indexStart, other._indexStart); + std::swap(_indexEnd, other._indexEnd); #endif - _indexOffset = other._indexOffset; - _indexType = other._indexType; - _indexBuffer = other._indexBuffer; - _attributes = std::move(other._attributes); + std::swap(_indexOffset, other._indexOffset); + std::swap(_indexType, other._indexType); + std::swap(_indexBuffer, other._indexBuffer); + std::swap(_attributes, other._attributes); #ifndef MAGNUM_TARGET_GLES2 - _integerAttributes = std::move(other._integerAttributes); + std::swap(_integerAttributes, other._integerAttributes); #ifndef MAGNUM_TARGET_GLES - _longAttributes = std::move(other._longAttributes); + std::swap(_longAttributes, other._longAttributes); #endif #endif - other._id = 0; - return *this; } diff --git a/src/Mesh.h b/src/Mesh.h index c943afb38..f49a624c0 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -242,9 +242,6 @@ class MAGNUM_EXPORT Mesh { friend class Context; friend class MeshView; - Mesh(const Mesh&) = delete; - Mesh& operator=(const Mesh&) = delete; - public: /** * @brief Primitive type @@ -353,8 +350,11 @@ class MAGNUM_EXPORT Mesh { */ explicit Mesh(Primitive primitive = Primitive::Triangles); + /** @brief Copying is not allowed */ + Mesh(const Mesh&) = delete; + /** @brief Move constructor */ - Mesh(Mesh&& other); + Mesh(Mesh&& other) noexcept; /** * @brief Destructor @@ -364,8 +364,11 @@ class MAGNUM_EXPORT Mesh { */ ~Mesh(); + /** @brief Copying is not allowed */ + Mesh& operator=(const Mesh&) = delete; + /** @brief Move assignment */ - Mesh& operator=(Mesh&& other); + Mesh& operator=(Mesh&& other) noexcept; /** * @brief Index size