From f8b9c69b162f885ac02c75fd1e1fd2a69b928e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 3 Apr 2019 20:48:19 +0200 Subject: [PATCH] Don't use std::tie() on std::pair(). It's nice and all, but including the whole just for that is not worth it. --- src/Magnum/Animation/Player.hpp | 4 ++- src/Magnum/GL/CubeMapTexture.cpp | 28 +++++++-------- src/Magnum/Math/Test/BezierTest.cpp | 53 ++++++++++++++--------------- src/Magnum/PixelStorage.h | 32 ++++++++--------- 4 files changed, 56 insertions(+), 61 deletions(-) diff --git a/src/Magnum/Animation/Player.hpp b/src/Magnum/Animation/Player.hpp index 7321f1daa..1773b8b4c 100644 --- a/src/Magnum/Animation/Player.hpp +++ b/src/Magnum/Animation/Player.hpp @@ -239,7 +239,9 @@ template Containers::Optional> playe iteration. If we exceeded play count, stop the animation and give out value at duration end. */ } else { - std::tie(playIteration, key) = scaler(timeToUse, duration); + const std::pair scaled = scaler(timeToUse, duration); + playIteration = scaled.first; + key = scaled.second; if(playCount && playIteration >= playCount) { if(state != State::Paused) state = State::Stopped; /* Don't reset the startTime to disambiguate between explicitly diff --git a/src/Magnum/GL/CubeMapTexture.cpp b/src/Magnum/GL/CubeMapTexture.cpp index a57d5f9c0..2b51e919d 100644 --- a/src/Magnum/GL/CubeMapTexture.cpp +++ b/src/Magnum/GL/CubeMapTexture.cpp @@ -113,11 +113,11 @@ void CubeMapTexture::compressedImage(const Int level, CompressedImage3D& image) /* If the user-provided pixel storage doesn't tell us all properties about the compression, we need to ask GL for it */ - std::size_t dataOffset, dataSize; + std::pair dataOffsetSize; if(!image.storage().compressedBlockSize().product() || !image.storage().compressedBlockDataSize()) { - dataOffset = 0; - dataSize = (this->*Context::current().state().texture->getCubeLevelCompressedImageSizeImplementation)(level)*6; - } else std::tie(dataOffset, dataSize) = Magnum::Implementation::compressedImageDataOffsetSizeFor(image, size); + dataOffsetSize.first = 0; + dataOffsetSize.second = (this->*Context::current().state().texture->getCubeLevelCompressedImageSizeImplementation)(level)*6; + } else dataOffsetSize = Magnum::Implementation::compressedImageDataOffsetSizeFor(image, size); /* Internal texture format */ GLint format; @@ -125,12 +125,12 @@ void CubeMapTexture::compressedImage(const Int level, CompressedImage3D& image) /* Reallocate only if needed */ Containers::Array data{image.release()}; - if(data.size() < dataOffset + dataSize) - data = Containers::Array{dataOffset + dataSize}; + if(data.size() < dataOffsetSize.first + dataOffsetSize.second) + data = Containers::Array{dataOffsetSize.first + dataOffsetSize.second}; Buffer::unbindInternal(Buffer::TargetHint::PixelPack); Context::current().state().renderer->applyPixelStoragePack(image.storage()); - (this->*Context::current().state().texture->getFullCompressedCubeImageImplementation)(level, size.xy(), dataOffset, dataSize, data); + (this->*Context::current().state().texture->getFullCompressedCubeImageImplementation)(level, size.xy(), dataOffsetSize.first, dataOffsetSize.second, data); image = CompressedImage3D{image.storage(), CompressedPixelFormat(format), size, std::move(data)}; } @@ -146,25 +146,25 @@ void CubeMapTexture::compressedImage(const Int level, CompressedBufferImage3D& i /* If the user-provided pixel storage doesn't tell us all properties about the compression, we need to ask GL for it */ - std::size_t dataOffset, dataSize; + std::pair dataOffsetSize; if(!image.storage().compressedBlockSize().product() || !image.storage().compressedBlockDataSize()) { - dataOffset = 0; - dataSize = (this->*Context::current().state().texture->getCubeLevelCompressedImageSizeImplementation)(level)*6; - } else std::tie(dataOffset, dataSize) = Magnum::Implementation::compressedImageDataOffsetSizeFor(image, size); + dataOffsetSize.first = 0; + dataOffsetSize.second = (this->*Context::current().state().texture->getCubeLevelCompressedImageSizeImplementation)(level)*6; + } else dataOffsetSize = Magnum::Implementation::compressedImageDataOffsetSizeFor(image, size); /* Internal texture format */ GLint format; (this->*Context::current().state().texture->getCubeLevelParameterivImplementation)(level, GL_TEXTURE_INTERNAL_FORMAT, &format); /* Reallocate only if needed */ - if(image.dataSize() < dataOffset + dataSize) - image.setData(image.storage(), CompressedPixelFormat(format), size, {nullptr, dataOffset + dataSize}, usage); + if(image.dataSize() < dataOffsetSize.first + dataOffsetSize.second) + image.setData(image.storage(), CompressedPixelFormat(format), size, {nullptr, dataOffsetSize.first + dataOffsetSize.second}, usage); else image.setData(image.storage(), CompressedPixelFormat(format), size, nullptr, usage); image.buffer().bindInternal(Buffer::TargetHint::PixelPack); Context::current().state().renderer->applyPixelStoragePack(image.storage()); - (this->*Context::current().state().texture->getFullCompressedCubeImageImplementation)(level, size.xy(), dataOffset, dataSize, nullptr); + (this->*Context::current().state().texture->getFullCompressedCubeImageImplementation)(level, size.xy(), dataOffsetSize.first, dataOffsetSize.second, nullptr); } CompressedBufferImage3D CubeMapTexture::compressedImage(const Int level, CompressedBufferImage3D&& image, const BufferUsage usage) { diff --git a/src/Magnum/Math/Test/BezierTest.cpp b/src/Magnum/Math/Test/BezierTest.cpp index aaddcaf8f..2f55110c3 100644 --- a/src/Magnum/Math/Test/BezierTest.cpp +++ b/src/Magnum/Math/Test/BezierTest.cpp @@ -272,46 +272,43 @@ void BezierTest::valueCubic() { void BezierTest::subdivideLinear() { LinearBezier2D bezier{Vector2{0.0f, 0.0f}, Vector2{20.0f, 4.0f}}; - LinearBezier2D left, right; - std::tie(left, right) = bezier.subdivide(0.25f); - - CORRADE_COMPARE(left[0], bezier[0]); - CORRADE_COMPARE(left[1], right[0]); - CORRADE_COMPARE(right[1], bezier[1]); - CORRADE_COMPARE(left.value(0.8f), bezier.value(0.2f)); - CORRADE_COMPARE(right.value(0.33333f), bezier.value(0.5f)); - CORRADE_COMPARE(left, (LinearBezier2D{Vector2{0.0f, 0.0f}, Vector2{5.0f, 1.0f}})); - CORRADE_COMPARE(right, (LinearBezier2D{Vector2{5.0f, 1.0f}, Vector2{20.0f, 4.0f}})); + std::pair subdivided = bezier.subdivide(0.25f); + + CORRADE_COMPARE(subdivided.first[0], bezier[0]); + CORRADE_COMPARE(subdivided.first[1], subdivided.second[0]); + CORRADE_COMPARE(subdivided.second[1], bezier[1]); + CORRADE_COMPARE(subdivided.first.value(0.8f), bezier.value(0.2f)); + CORRADE_COMPARE(subdivided.second.value(0.33333f), bezier.value(0.5f)); + CORRADE_COMPARE(subdivided.first, (LinearBezier2D{Vector2{0.0f, 0.0f}, Vector2{5.0f, 1.0f}})); + CORRADE_COMPARE(subdivided.second, (LinearBezier2D{Vector2{5.0f, 1.0f}, Vector2{20.0f, 4.0f}})); } void BezierTest::subdivideQuadratic() { QuadraticBezier2D bezier{Vector2{0.0f, 0.0f}, Vector2{10.0f, 15.0f}, Vector2{20.0f, 4.0f}}; - QuadraticBezier2D left, right; - std::tie(left, right) = bezier.subdivide(0.25f); + std::pair subdivided = bezier.subdivide(0.25f); - CORRADE_COMPARE(left[0], bezier[0]); - CORRADE_COMPARE(left[2], right[0]); - CORRADE_COMPARE(right[2], bezier[2]); - CORRADE_COMPARE(left.value(0.8f), bezier.value(0.2f)); - CORRADE_COMPARE(right.value(0.33333f), bezier.value(0.5f)); - CORRADE_COMPARE(left, (QuadraticBezier2D{Vector2{0.0f, 0.0f}, Vector2{2.5f, 3.75f}, Vector2{5.0f, 5.875f}})); - CORRADE_COMPARE(right, (QuadraticBezier2D{Vector2{5.0f, 5.875f}, Vector2{12.5f, 12.25f}, Vector2{20.0f, 4.0f}})); + CORRADE_COMPARE(subdivided.first[0], bezier[0]); + CORRADE_COMPARE(subdivided.first[2], subdivided.second[0]); + CORRADE_COMPARE(subdivided.second[2], bezier[2]); + CORRADE_COMPARE(subdivided.first.value(0.8f), bezier.value(0.2f)); + CORRADE_COMPARE(subdivided.second.value(0.33333f), bezier.value(0.5f)); + CORRADE_COMPARE(subdivided.first, (QuadraticBezier2D{Vector2{0.0f, 0.0f}, Vector2{2.5f, 3.75f}, Vector2{5.0f, 5.875f}})); + CORRADE_COMPARE(subdivided.second, (QuadraticBezier2D{Vector2{5.0f, 5.875f}, Vector2{12.5f, 12.25f}, Vector2{20.0f, 4.0f}})); } void BezierTest::subdivideCubic() { CubicBezier2D bezier{Vector2{0.0f, 0.0f}, Vector2{10.0f, 15.0f}, Vector2{20.0f, 4.0f}, Vector2{5.0f, -20.0f}}; - CubicBezier2D left, right; - std::tie(left, right) = bezier.subdivide(0.25f); + std::pair subdivided = bezier.subdivide(0.25f); - CORRADE_COMPARE(left[0], bezier[0]); - CORRADE_COMPARE(left[3], right[0]); - CORRADE_COMPARE(right[3], bezier[3]); - CORRADE_COMPARE(left.value(0.8f), bezier.value(0.2f)); - CORRADE_COMPARE(right.value(0.33333f), bezier.value(0.5f)); - CORRADE_COMPARE(left, (CubicBezier2D{Vector2{0.0f, 0.0f}, Vector2{2.5f, 3.75f}, Vector2{5.0f, 5.875f}, Vector2{7.10938f, 6.57812f}})); - CORRADE_COMPARE(right, (CubicBezier2D{Vector2{7.10938f, 6.57812f}, Vector2{13.4375f, 8.6875f}, Vector2{16.25f, -2.0f}, Vector2{5.0f, -20.0f}})); + CORRADE_COMPARE(subdivided.first[0], bezier[0]); + CORRADE_COMPARE(subdivided.first[3], subdivided.second[0]); + CORRADE_COMPARE(subdivided.second[3], bezier[3]); + CORRADE_COMPARE(subdivided.first.value(0.8f), bezier.value(0.2f)); + CORRADE_COMPARE(subdivided.second.value(0.33333f), bezier.value(0.5f)); + CORRADE_COMPARE(subdivided.first, (CubicBezier2D{Vector2{0.0f, 0.0f}, Vector2{2.5f, 3.75f}, Vector2{5.0f, 5.875f}, Vector2{7.10938f, 6.57812f}})); + CORRADE_COMPARE(subdivided.second, (CubicBezier2D{Vector2{7.10938f, 6.57812f}, Vector2{13.4375f, 8.6875f}, Vector2{16.25f, -2.0f}, Vector2{5.0f, -20.0f}})); } void BezierTest::strictWeakOrdering() { diff --git a/src/Magnum/PixelStorage.h b/src/Magnum/PixelStorage.h index cd787e437..e3ee92482 100644 --- a/src/Magnum/PixelStorage.h +++ b/src/Magnum/PixelStorage.h @@ -248,35 +248,32 @@ constexpr PixelStorage::PixelStorage() noexcept: _rowLength{0}, _imageHeight{0}, namespace Implementation { /* Used in *Image::dataProperties() */ template std::pair, Math::Vector> imageDataProperties(const T& image) { - Math::Vector3 offset, dataSize; - std::tie(offset, dataSize) = image.storage().dataProperties(image.pixelSize(), Vector3i::pad(image.size(), 1)); - return std::make_pair(Math::Vector::pad(offset), Math::Vector::pad(dataSize)); + std::pair, Math::Vector3> dataProperties = image.storage().dataProperties(image.pixelSize(), Vector3i::pad(image.size(), 1)); + return std::make_pair(Math::Vector::pad(dataProperties.first), Math::Vector::pad(dataProperties.second)); } /* Used in Compressed*Image::dataProperties() */ template std::pair, Math::Vector> compressedImageDataProperties(const T& image) { - Math::Vector3 offset, blockCount; - std::tie(offset, blockCount) = image.storage().dataProperties(Vector3i::pad(image.size(), 1)); - return std::make_pair(Math::Vector::pad(offset), Math::Vector::pad(blockCount)); + std::pair, Math::Vector3> dataProperties = image.storage().dataProperties(Vector3i::pad(image.size(), 1)); + return std::make_pair(Math::Vector::pad(dataProperties.first), Math::Vector::pad(dataProperties.second)); } /* Used in image query functions */ template std::size_t imageDataSizeFor(const T& image, const Math::Vector& size) { - Math::Vector3 offset, dataSize; - std::tie(offset, dataSize) = image.storage().dataProperties(image.pixelSize(), Vector3i::pad(size, 1)); + std::pair, Math::Vector3> dataProperties = image.storage().dataProperties(image.pixelSize(), Vector3i::pad(size, 1)); /* Smallest line/rectangle/cube that covers the area */ std::size_t dataOffset = 0; - if(offset.z()) - dataOffset += offset.z(); - else if(offset.y()) { + if(dataProperties.first.z()) + dataOffset += dataProperties.first.z(); + else if(dataProperties.first.y()) { if(!image.storage().imageHeight()) - dataOffset += offset.y(); - } else if(offset.x()) { + dataOffset += dataProperties.first.y(); + } else if(dataProperties.first.x()) { if(!image.storage().rowLength()) - dataOffset += offset.x(); + dataOffset += dataProperties.first.x(); } - return dataOffset + dataSize.product(); + return dataOffset + dataProperties.second.product(); } /* Used in data size assertions */ @@ -287,12 +284,11 @@ namespace Implementation { template std::pair compressedImageDataOffsetSizeFor(const T& image, const Math::Vector& size) { CORRADE_INTERNAL_ASSERT(image.storage().compressedBlockSize().product() && image.storage().compressedBlockDataSize()); - Math::Vector3 offset, blockCount; - std::tie(offset, blockCount) = image.storage().dataProperties(Vector3i::pad(size, 1)); + std::pair, Math::Vector3> dataProperties = image.storage().dataProperties(Vector3i::pad(size, 1)); const auto realBlockCount = Math::Vector3{(Vector3i::pad(size, 1) + image.storage().compressedBlockSize() - Vector3i{1})/image.storage().compressedBlockSize()}; - return {offset.sum(), (blockCount.product() - (blockCount.x() - realBlockCount.x()) - (blockCount.y() - realBlockCount.y())*blockCount.x())*image.storage().compressedBlockDataSize()}; + return {dataProperties.first.sum(), (dataProperties.second.product() - (dataProperties.second.x() - realBlockCount.x()) - (dataProperties.second.y() - realBlockCount.y())*dataProperties.second.x())*image.storage().compressedBlockDataSize()}; } /* Used in image query functions */