From b24ffa4a3e11256e9aa61633e0561db2543712a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 24 Mar 2019 01:47:09 +0100 Subject: [PATCH] Use min() / max() / minmax() from Math instead of std::. First step to avoid the header. --- src/Magnum/GL/AbstractShaderProgram.cpp | 4 ++-- src/Magnum/GL/Shader.cpp | 5 +++-- src/Magnum/Math/Test/QuaternionTest.cpp | 6 +++--- src/Magnum/Math/Test/TypeTraitsTest.cpp | 3 --- src/Magnum/MeshTools/CompressIndices.cpp | 14 +++++++------- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Magnum/GL/AbstractShaderProgram.cpp b/src/Magnum/GL/AbstractShaderProgram.cpp index cd831eb99..c3b02393e 100644 --- a/src/Magnum/GL/AbstractShaderProgram.cpp +++ b/src/Magnum/GL/AbstractShaderProgram.cpp @@ -327,7 +327,7 @@ std::pair AbstractShaderProgram::validate() { std::string message(logLength, '\n'); if(message.size() > 1) glGetProgramInfoLog(_id, message.size(), nullptr, &message[0]); - message.resize(std::max(logLength, 1)-1); + message.resize(Math::max(logLength, 1)-1); return {success, std::move(message)}; } @@ -415,7 +415,7 @@ bool AbstractShaderProgram::link(std::initializer_list 1) glGetProgramInfoLog(shader._id, message.size(), nullptr, &message[0]); - message.resize(std::max(logLength, 1)-1); + message.resize(Math::max(logLength, 1)-1); /* Show error log */ if(!success) { diff --git a/src/Magnum/GL/Shader.cpp b/src/Magnum/GL/Shader.cpp index c1ff0ada7..fefa44610 100644 --- a/src/Magnum/GL/Shader.cpp +++ b/src/Magnum/GL/Shader.cpp @@ -38,6 +38,7 @@ #endif #include "Magnum/GL/Implementation/State.h" #include "Magnum/GL/Implementation/ShaderState.h" +#include "Magnum/Math/Functions.h" /* libgles-omap3-dev_4.03.00.02-r15.6 on BeagleBoard/Ångström linux 2011.3 doesn't have GLchar */ #ifdef MAGNUM_TARGET_GLES @@ -757,7 +758,7 @@ bool Shader::compile(std::initializer_list> shader std::size_t maxSourceCount = 0; for(Shader& shader: shaders) { CORRADE_ASSERT(shader._sources.size() > 1, "GL::Shader::compile(): no files added", false); - maxSourceCount = std::max(shader._sources.size(), maxSourceCount); + maxSourceCount = Math::max(shader._sources.size(), maxSourceCount); } /** @todo ArrayTuple/VLAs */ Containers::Array pointers(maxSourceCount); @@ -788,7 +789,7 @@ bool Shader::compile(std::initializer_list> shader std::string message(logLength, '\0'); if(message.size() > 1) glGetShaderInfoLog(shader._id, message.size(), nullptr, &message[0]); - message.resize(std::max(logLength, 1)-1); + message.resize(Math::max(logLength, 1)-1); /* Show error log */ if(!success) { diff --git a/src/Magnum/Math/Test/QuaternionTest.cpp b/src/Magnum/Math/Test/QuaternionTest.cpp index 0992cffb0..2d81022b0 100644 --- a/src/Magnum/Math/Test/QuaternionTest.cpp +++ b/src/Magnum/Math/Test/QuaternionTest.cpp @@ -511,7 +511,7 @@ void QuaternionTest::matrix() { Quaternion q2 = Quaternion::rotation(Deg(130.0f), axis); CORRADE_COMPARE_AS(m2.trace(), 0.0f, Corrade::TestSuite::Compare::Less); CORRADE_COMPARE_AS(m2.diagonal()[2], - std::max(m2.diagonal()[0], m2.diagonal()[1]), + Math::max(m2.diagonal()[0], m2.diagonal()[1]), Corrade::TestSuite::Compare::Greater); CORRADE_COMPARE(Quaternion::fromMatrix(m2), q2); @@ -521,7 +521,7 @@ void QuaternionTest::matrix() { Quaternion q3 = Quaternion::rotation(Deg(130.0f), axis2); CORRADE_COMPARE_AS(m3.trace(), 0.0f, Corrade::TestSuite::Compare::Less); CORRADE_COMPARE_AS(m3.diagonal()[1], - std::max(m3.diagonal()[0], m3.diagonal()[2]), + Math::max(m3.diagonal()[0], m3.diagonal()[2]), Corrade::TestSuite::Compare::Greater); CORRADE_COMPARE(Quaternion::fromMatrix(m3), q3); @@ -531,7 +531,7 @@ void QuaternionTest::matrix() { Quaternion q4 = Quaternion::rotation(Deg(130.0f), axis3); CORRADE_COMPARE_AS(m4.trace(), 0.0f, Corrade::TestSuite::Compare::Less); CORRADE_COMPARE_AS(m4.diagonal()[0], - std::max(m4.diagonal()[1], m4.diagonal()[2]), + Math::max(m4.diagonal()[1], m4.diagonal()[2]), Corrade::TestSuite::Compare::Greater); CORRADE_COMPARE(Quaternion::fromMatrix(m4), q4); } diff --git a/src/Magnum/Math/Test/TypeTraitsTest.cpp b/src/Magnum/Math/Test/TypeTraitsTest.cpp index ca4d25d8b..27bccf8af 100644 --- a/src/Magnum/Math/Test/TypeTraitsTest.cpp +++ b/src/Magnum/Math/Test/TypeTraitsTest.cpp @@ -24,9 +24,6 @@ */ #include -#ifdef _MSC_VER -#include /* std::max() */ -#endif #include "Magnum/Math/TypeTraits.h" #include "Magnum/Math/Constants.h" diff --git a/src/Magnum/MeshTools/CompressIndices.cpp b/src/Magnum/MeshTools/CompressIndices.cpp index c13d1454d..03f935e3c 100644 --- a/src/Magnum/MeshTools/CompressIndices.cpp +++ b/src/Magnum/MeshTools/CompressIndices.cpp @@ -26,8 +26,8 @@ #include "CompressIndices.h" #include -#include #include +#include #include "Magnum/Math/Functions.h" @@ -49,10 +49,10 @@ template inline Containers::Array compress(const std::vector, MeshIndexType, UnsignedInt, UnsignedInt> compressIndices(const std::vector& indices) { /** @todo Performance hint when range can be represented by smaller value? */ - const auto minmax = std::minmax_element(indices.begin(), indices.end()); + const auto minmax = Math::minmax(indices); Containers::Array data; MeshIndexType type; - switch(Math::log(256, *minmax.second)) { + switch(Math::log(256, minmax.second)) { case 0: data = compress(indices); type = MeshIndexType::UnsignedByte; @@ -68,16 +68,16 @@ std::tuple, MeshIndexType, UnsignedInt, UnsignedInt> com break; default: - CORRADE_ASSERT(false, "MeshTools::compressIndices(): no type able to index" << *minmax.second << "elements.", {}); + CORRADE_ASSERT(false, "MeshTools::compressIndices(): no type able to index" << minmax.second << "elements.", {}); } - return std::make_tuple(std::move(data), type, *minmax.first, *minmax.second); + return std::make_tuple(std::move(data), type, minmax.first, minmax.second); } template Containers::Array compressIndicesAs(const std::vector& indices) { #if !defined(CORRADE_NO_ASSERT) || defined(CORRADE_GRACEFUL_ASSERT) - const auto max = std::max_element(indices.begin(), indices.end()); - CORRADE_ASSERT(Math::log(256, *max) < sizeof(T), "MeshTools::compressIndicesAs(): type too small to represent value" << *max, {}); + const auto max = Math::max(indices); + CORRADE_ASSERT(Math::log(256, max) < sizeof(T), "MeshTools::compressIndicesAs(): type too small to represent value" << max, {}); #endif Containers::Array buffer(indices.size());