Browse Source

Properly use the "Std Swap Two Step".

I hate this. Why it isn't intuitive like proposed in here?
http://ericniebler.com/2014/10/21/customization-point-design-in-c11-and-beyond/
pull/94/head
Vladimír Vondruš 11 years ago
parent
commit
65a2e5677a
  1. 5
      src/Magnum/AbstractQuery.h
  2. 3
      src/Magnum/AbstractShaderProgram.cpp
  3. 7
      src/Magnum/AbstractTexture.h
  4. 3
      src/Magnum/Audio/Buffer.h
  5. 3
      src/Magnum/Audio/Source.h
  6. 9
      src/Magnum/Buffer.h
  7. 5
      src/Magnum/BufferImage.h
  8. 7
      src/Magnum/Framebuffer.h
  9. 5
      src/Magnum/Image.h
  10. 5
      src/Magnum/Math/Algorithms/GaussJordan.h
  11. 3
      src/Magnum/Math/Functions.h
  12. 31
      src/Magnum/Mesh.cpp
  13. 3
      src/Magnum/MeshTools/CombineIndexedArrays.h
  14. 3
      src/Magnum/MeshTools/FlipNormals.cpp
  15. 3
      src/Magnum/MeshTools/Tipsify.cpp
  16. 5
      src/Magnum/Renderbuffer.h
  17. 7
      src/Magnum/Shader.h
  18. 5
      src/Magnum/Shapes/Composition.cpp
  19. 5
      src/Magnum/Trade/ImageData.h
  20. 5
      src/Magnum/TransformFeedback.h

5
src/Magnum/AbstractQuery.h

@ -186,8 +186,9 @@ inline AbstractQuery::AbstractQuery(AbstractQuery&& other) noexcept: _id(other._
} }
inline AbstractQuery& AbstractQuery::operator=(AbstractQuery&& other) noexcept { inline AbstractQuery& AbstractQuery::operator=(AbstractQuery&& other) noexcept {
std::swap(_id, other._id); using std::swap;
std::swap(_target, other._target); swap(_id, other._id);
swap(_target, other._target);
return *this; return *this;
} }

3
src/Magnum/AbstractShaderProgram.cpp

@ -245,7 +245,8 @@ AbstractShaderProgram::~AbstractShaderProgram() {
} }
AbstractShaderProgram& AbstractShaderProgram::operator=(AbstractShaderProgram&& other) noexcept { AbstractShaderProgram& AbstractShaderProgram::operator=(AbstractShaderProgram&& other) noexcept {
std::swap(_id, other._id); using std::swap;
swap(_id, other._id);
return *this; return *this;
} }

7
src/Magnum/AbstractTexture.h

@ -638,9 +638,10 @@ inline AbstractTexture::AbstractTexture(AbstractTexture&& other) noexcept: _targ
} }
inline AbstractTexture& AbstractTexture::operator=(AbstractTexture&& other) noexcept { inline AbstractTexture& AbstractTexture::operator=(AbstractTexture&& other) noexcept {
std::swap(_target, other._target); using std::swap;
std::swap(_id, other._id); swap(_target, other._target);
std::swap(_created, other._created); swap(_id, other._id);
swap(_created, other._created);
return *this; return *this;
} }

3
src/Magnum/Audio/Buffer.h

@ -112,7 +112,8 @@ inline Buffer::Buffer(Buffer&& other): _id(other._id) {
} }
inline Buffer& Buffer::operator=(Buffer&& other) { inline Buffer& Buffer::operator=(Buffer&& other) {
std::swap(_id, other._id); using std::swap;
swap(_id, other._id);
return *this; return *this;
} }

3
src/Magnum/Audio/Source.h

@ -594,7 +594,8 @@ inline Source::Source(Source&& other): _id(other._id) {
} }
inline Source& Source::operator=(Source&& other) { inline Source& Source::operator=(Source&& other) {
std::swap(_id, other._id); using std::swap;
swap(_id, other._id);
return *this; return *this;
} }

9
src/Magnum/Buffer.h

@ -1307,12 +1307,13 @@ inline Buffer::Buffer(Buffer&& other) noexcept: _id{other._id}, _targetHint{othe
} }
inline Buffer& Buffer::operator=(Buffer&& other) noexcept { inline Buffer& Buffer::operator=(Buffer&& other) noexcept {
std::swap(_id, other._id); using std::swap;
std::swap(_targetHint, other._targetHint); swap(_id, other._id);
swap(_targetHint, other._targetHint);
#ifdef CORRADE_TARGET_NACL #ifdef CORRADE_TARGET_NACL
std::swap(_mappedBuffer, other._mappedBuffer); swap(_mappedBuffer, other._mappedBuffer);
#endif #endif
std::swap(_created, other._created); swap(_created, other._created);
return *this; return *this;
} }

5
src/Magnum/BufferImage.h

@ -145,8 +145,9 @@ template<UnsignedInt dimensions> inline BufferImage<dimensions>::BufferImage(Buf
template<UnsignedInt dimensions> inline BufferImage<dimensions>& BufferImage<dimensions>::operator=(BufferImage<dimensions>&& other) noexcept { template<UnsignedInt dimensions> inline BufferImage<dimensions>& BufferImage<dimensions>::operator=(BufferImage<dimensions>&& other) noexcept {
AbstractImage::operator=(std::move(other)); AbstractImage::operator=(std::move(other));
std::swap(_size, other._size); using std::swap;
std::swap(_buffer, other._buffer); swap(_size, other._size);
swap(_buffer, other._buffer);
return *this; return *this;
} }
#else #else

7
src/Magnum/Framebuffer.h

@ -701,9 +701,10 @@ inline Framebuffer::Framebuffer(Framebuffer&& other) noexcept {
} }
inline Framebuffer& Framebuffer::operator=(Framebuffer&& other) noexcept { inline Framebuffer& Framebuffer::operator=(Framebuffer&& other) noexcept {
std::swap(_id, other._id); using std::swap;
std::swap(_viewport, other._viewport); swap(_id, other._id);
std::swap(_created, other._created); swap(_viewport, other._viewport);
swap(_created, other._created);
return *this; return *this;
} }

5
src/Magnum/Image.h

@ -165,8 +165,9 @@ template<UnsignedInt dimensions> inline Image<dimensions>::Image(Image<dimension
template<UnsignedInt dimensions> inline Image<dimensions>& Image<dimensions>::operator=(Image<dimensions>&& other) noexcept { template<UnsignedInt dimensions> inline Image<dimensions>& Image<dimensions>::operator=(Image<dimensions>&& other) noexcept {
AbstractImage::operator=(std::move(other)); AbstractImage::operator=(std::move(other));
std::swap(_size, other._size); using std::swap;
std::swap(_data, other._data); swap(_size, other._size);
swap(_data, other._data);
return *this; return *this;
} }

5
src/Magnum/Math/Algorithms/GaussJordan.h

@ -62,8 +62,9 @@ template<std::size_t size, std::size_t rows, class T> bool gaussJordanInPlaceTra
rowMax = row2; rowMax = row2;
/* Swap the rows */ /* Swap the rows */
std::swap(a[row], a[rowMax]); using std::swap;
std::swap(t[row], t[rowMax]); swap(a[row], a[rowMax]);
swap(t[row], t[rowMax]);
/* Singular */ /* Singular */
if(TypeTraits<T>::equals(a[row][row], T(0))) if(TypeTraits<T>::equals(a[row][row], T(0)))

3
src/Magnum/Math/Functions.h

@ -190,9 +190,10 @@ template<class T> inline typename std::enable_if<std::is_arithmetic<T>::value, s
return a < b ? std::make_pair(a, b) : std::make_pair(b, a); return a < b ? std::make_pair(a, b) : std::make_pair(b, a);
} }
template<std::size_t size, class T> std::pair<Vector<size, T>, Vector<size, T>> minmax(const Vector<size, T>& a, const Vector<size, T>& b) { template<std::size_t size, class T> std::pair<Vector<size, T>, Vector<size, T>> minmax(const Vector<size, T>& a, const Vector<size, T>& b) {
using std::swap;
std::pair<Vector<size, T>, Vector<size, T>> out{a, b}; std::pair<Vector<size, T>, Vector<size, T>> out{a, b};
for(std::size_t i = 0; i != size; ++i) for(std::size_t i = 0; i != size; ++i)
if(out.first[i] > out.second[i]) std::swap(out.first[i], out.second[i]); if(out.first[i] > out.second[i]) swap(out.first[i], out.second[i]);
return out; return out;
} }
#endif #endif

31
src/Magnum/Mesh.cpp

@ -132,27 +132,28 @@ Mesh::Mesh(Mesh&& other) noexcept: _id(other._id), _created{other._created}, _pr
} }
Mesh& Mesh::operator=(Mesh&& other) noexcept { Mesh& Mesh::operator=(Mesh&& other) noexcept {
std::swap(_id, other._id); using std::swap;
std::swap(_created, other._created); swap(_id, other._id);
std::swap(_primitive, other._primitive); swap(_created, other._created);
std::swap(_count, other._count); swap(_primitive, other._primitive);
std::swap(_baseVertex, other._baseVertex); swap(_count, other._count);
std::swap(_instanceCount, other._instanceCount); swap(_baseVertex, other._baseVertex);
swap(_instanceCount, other._instanceCount);
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
std::swap(_baseInstance, other._baseInstance); swap(_baseInstance, other._baseInstance);
#endif #endif
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
std::swap(_indexStart, other._indexStart); swap(_indexStart, other._indexStart);
std::swap(_indexEnd, other._indexEnd); swap(_indexEnd, other._indexEnd);
#endif #endif
std::swap(_indexOffset, other._indexOffset); swap(_indexOffset, other._indexOffset);
std::swap(_indexType, other._indexType); swap(_indexType, other._indexType);
std::swap(_indexBuffer, other._indexBuffer); swap(_indexBuffer, other._indexBuffer);
std::swap(_attributes, other._attributes); swap(_attributes, other._attributes);
#ifndef MAGNUM_TARGET_GLES2 #ifndef MAGNUM_TARGET_GLES2
std::swap(_integerAttributes, other._integerAttributes); swap(_integerAttributes, other._integerAttributes);
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
std::swap(_longAttributes, other._longAttributes); swap(_longAttributes, other._longAttributes);
#endif #endif
#endif #endif

3
src/Magnum/MeshTools/CombineIndexedArrays.h

@ -131,7 +131,8 @@ template<class T> void writeCombinedArray(const UnsignedInt stride, const Unsign
CORRADE_ASSERT(index < array.size(), "MeshTools::combineIndexedArrays(): index out of range", ); CORRADE_ASSERT(index < array.size(), "MeshTools::combineIndexedArrays(): index out of range", );
output.push_back(array[index]); output.push_back(array[index]);
} }
std::swap(output, array); using std::swap;
swap(output, array);
} }
/* Terminator for recursive calls */ /* Terminator for recursive calls */

3
src/Magnum/MeshTools/FlipNormals.cpp

@ -32,8 +32,9 @@ namespace Magnum { namespace MeshTools {
void flipFaceWinding(std::vector<UnsignedInt>& indices) { void flipFaceWinding(std::vector<UnsignedInt>& indices) {
CORRADE_ASSERT(!(indices.size()%3), "MeshTools::flipNormals(): index count is not divisible by 3!", ); CORRADE_ASSERT(!(indices.size()%3), "MeshTools::flipNormals(): index count is not divisible by 3!", );
using std::swap;
for(std::size_t i = 0; i != indices.size(); i += 3) for(std::size_t i = 0; i != indices.size(); i += 3)
std::swap(indices[i+1], indices[i+2]); swap(indices[i+1], indices[i+2]);
} }
void flipNormals(std::vector<Vector3>& normals) { void flipNormals(std::vector<Vector3>& normals) {

3
src/Magnum/MeshTools/Tipsify.cpp

@ -125,7 +125,8 @@ void Tipsify::operator()(std::size_t cacheSize) {
} }
/* Swap original index buffer with optimized */ /* Swap original index buffer with optimized */
std::swap(indices, outputIndices); using std::swap;
swap(indices, outputIndices);
} }
void Tipsify::buildAdjacency(std::vector<UnsignedInt>& liveTriangleCount, std::vector<UnsignedInt>& neighborOffset, std::vector<UnsignedInt>& neighbors) const { void Tipsify::buildAdjacency(std::vector<UnsignedInt>& liveTriangleCount, std::vector<UnsignedInt>& neighborOffset, std::vector<UnsignedInt>& neighbors) const {

5
src/Magnum/Renderbuffer.h

@ -222,8 +222,9 @@ inline Renderbuffer::Renderbuffer(Renderbuffer&& other) noexcept: _id{other._id}
} }
inline Renderbuffer& Renderbuffer::operator=(Renderbuffer&& other) noexcept { inline Renderbuffer& Renderbuffer::operator=(Renderbuffer&& other) noexcept {
std::swap(_id, other._id); using std::swap;
std::swap(_created, other._created); swap(_id, other._id);
swap(_created, other._created);
return *this; return *this;
} }

7
src/Magnum/Shader.h

@ -576,9 +576,10 @@ inline Shader::Shader(Shader&& other) noexcept: _type(other._type), _id(other._i
} }
inline Shader& Shader::operator=(Shader&& other) noexcept { inline Shader& Shader::operator=(Shader&& other) noexcept {
std::swap(_type, other._type); using std::swap;
std::swap(_id, other._id); swap(_type, other._type);
std::swap(_sources, other._sources); swap(_id, other._id);
swap(_sources, other._sources);
return *this; return *this;
} }

5
src/Magnum/Shapes/Composition.cpp

@ -91,8 +91,9 @@ template<UnsignedInt dimensions> Composition<dimensions>& Composition<dimensions
} }
template<UnsignedInt dimensions> Composition<dimensions>& Composition<dimensions>::operator=(Composition<dimensions>&& other) { template<UnsignedInt dimensions> Composition<dimensions>& Composition<dimensions>::operator=(Composition<dimensions>&& other) {
std::swap(other._shapes, _shapes); using std::swap;
std::swap(other._nodes, _nodes); swap(other._shapes, _shapes);
swap(other._nodes, _nodes);
return *this; return *this;
} }

5
src/Magnum/Trade/ImageData.h

@ -136,8 +136,9 @@ template<UnsignedInt dimensions> inline ImageData<dimensions>::ImageData(ImageDa
template<UnsignedInt dimensions> inline ImageData<dimensions>& ImageData<dimensions>::operator=(ImageData<dimensions>&& other) noexcept { template<UnsignedInt dimensions> inline ImageData<dimensions>& ImageData<dimensions>::operator=(ImageData<dimensions>&& other) noexcept {
AbstractImage::operator=(std::move(other)); AbstractImage::operator=(std::move(other));
std::swap(_size, other._size); using std::swap;
std::swap(_data, other._data); swap(_size, other._size);
swap(_data, other._data);
return *this; return *this;
} }

5
src/Magnum/TransformFeedback.h

@ -376,8 +376,9 @@ inline TransformFeedback::TransformFeedback(TransformFeedback&& other) noexcept:
} }
inline TransformFeedback& TransformFeedback::operator=(TransformFeedback&& other) noexcept { inline TransformFeedback& TransformFeedback::operator=(TransformFeedback&& other) noexcept {
std::swap(_id, other._id); using std::swap;
std::swap(_created, other._created); swap(_id, other._id);
swap(_created, other._created);
return *this; return *this;
} }

Loading…
Cancel
Save