diff --git a/doc/snippets/MagnumMath.cpp b/doc/snippets/MagnumMath.cpp index faf3e2eca..fe01fea7c 100644 --- a/doc/snippets/MagnumMath.cpp +++ b/doc/snippets/MagnumMath.cpp @@ -23,6 +23,9 @@ DEALINGS IN THE SOFTWARE. */ +#include +#include + #include "Magnum/Magnum.h" #include "Magnum/Math/Color.h" #include "Magnum/Math/Bezier.h" @@ -34,9 +37,6 @@ #include "Magnum/Math/Algorithms/GramSchmidt.h" #include "Magnum/Math/StrictWeakOrdering.h" -#include -#include - using namespace Magnum; using namespace Magnum::Math::Literals; diff --git a/src/Magnum/Math/Bezier.h b/src/Magnum/Math/Bezier.h index a46f0caa3..6d3c30965 100644 --- a/src/Magnum/Math/Bezier.h +++ b/src/Magnum/Math/Bezier.h @@ -318,6 +318,7 @@ extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utili #endif namespace Implementation { + template struct StrictWeakOrdering> { bool operator()(const Bezier& a, const Bezier& b) const { StrictWeakOrdering> o; @@ -328,9 +329,10 @@ template struct StrictWeakOr return false; } - return false; // a and b are equivalent + return false; /* a and b are equivalent */ } }; + } }} diff --git a/src/Magnum/Math/BoolVector.h b/src/Magnum/Math/BoolVector.h index 9364d0c7b..7379aad43 100644 --- a/src/Magnum/Math/BoolVector.h +++ b/src/Magnum/Math/BoolVector.h @@ -304,8 +304,8 @@ template inline BoolVector BoolVector::operator~() return out; } -/* Specialization of helper types*/ namespace Implementation { + template struct StrictWeakOrdering> { bool operator()(const BoolVector& a, const BoolVector& b) const { auto ad = a.data(); @@ -317,12 +317,13 @@ template struct StrictWeakOrdering> { return false; } - // mask last element with to hide unused bits + /* Mask last element with to hide padding bits */ constexpr UnsignedByte mask = UnsignedByte(0xFF) >> (BoolVector::DataSize * 8 - size); constexpr std::size_t i = BoolVector::DataSize - 1; return (ad[i] & mask) < (bd[i] & mask); } }; + } }} diff --git a/src/Magnum/Math/Color.h b/src/Magnum/Math/Color.h index 6dd059f78..aa0ab1339 100644 --- a/src/Magnum/Math/Color.h +++ b/src/Magnum/Math/Color.h @@ -1273,9 +1273,8 @@ namespace Implementation { template struct TypeForSize<4, Color3> { typedef Color4 Type; }; template struct TypeForSize<4, Color4> { typedef Color4 Type; }; - template struct StrictWeakOrdering> : public StrictWeakOrdering> {}; - template struct StrictWeakOrdering> : public StrictWeakOrdering> {}; - + template struct StrictWeakOrdering>: StrictWeakOrdering> {}; + template struct StrictWeakOrdering>: StrictWeakOrdering> {}; } }} diff --git a/src/Magnum/Math/Complex.h b/src/Magnum/Math/Complex.h index 4f5c4f885..9704b03c3 100644 --- a/src/Magnum/Math/Complex.h +++ b/src/Magnum/Math/Complex.h @@ -620,8 +620,8 @@ extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utili extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug&, const Complex&); #endif -/* Specialization of helper types*/ namespace Implementation { + template struct StrictWeakOrdering> { bool operator()(const Complex& a, const Complex& b) const { if(a.real() < b.real()) @@ -632,6 +632,7 @@ template struct StrictWeakOrdering> { return a.imaginary() < b.imaginary(); } }; + } }} diff --git a/src/Magnum/Math/CubicHermite.h b/src/Magnum/Math/CubicHermite.h index 480261d4c..b6868df27 100644 --- a/src/Magnum/Math/CubicHermite.h +++ b/src/Magnum/Math/CubicHermite.h @@ -539,6 +539,7 @@ template inline bool CubicHermite::operator==(const CubicHermite& } namespace Implementation { + template struct StrictWeakOrdering> { bool operator()(const CubicHermite& a, const CubicHermite& b) const { StrictWeakOrdering o; @@ -553,6 +554,7 @@ template struct StrictWeakOrdering> { return o(a.outTangent(), b.outTangent()); } }; + } }} diff --git a/src/Magnum/Math/Dual.h b/src/Magnum/Math/Dual.h index 8f8ef1319..c1b1b18aa 100644 --- a/src/Magnum/Math/Dual.h +++ b/src/Magnum/Math/Dual.h @@ -395,8 +395,8 @@ template std::pair, Dual> sincos(const Dual>& a template std::pair, Dual> sincos(const Dual>& angle) { return sincos(Dual>(angle)); } #endif -/* Specialization of helper types*/ namespace Implementation { + template struct StrictWeakOrdering> { bool operator()(const Dual& a, const Dual& b) const { StrictWeakOrdering o; @@ -408,6 +408,7 @@ template struct StrictWeakOrdering> { return o(a.dual(), b.dual()); } }; + } }} diff --git a/src/Magnum/Math/DualComplex.h b/src/Magnum/Math/DualComplex.h index 7f86fc1b5..bf6b1823a 100644 --- a/src/Magnum/Math/DualComplex.h +++ b/src/Magnum/Math/DualComplex.h @@ -385,9 +385,8 @@ extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utili extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug&, const DualComplex&); #endif -/* Specialization of helper types*/ namespace Implementation { -template struct StrictWeakOrdering>: public StrictWeakOrdering>> {}; + template struct StrictWeakOrdering>: StrictWeakOrdering>> {}; } }} diff --git a/src/Magnum/Math/DualQuaternion.h b/src/Magnum/Math/DualQuaternion.h index ab1716084..93a77db30 100644 --- a/src/Magnum/Math/DualQuaternion.h +++ b/src/Magnum/Math/DualQuaternion.h @@ -545,9 +545,8 @@ extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utili extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug&, const DualQuaternion&); #endif -/* Specialization of helper types*/ namespace Implementation { -template struct StrictWeakOrdering>: public StrictWeakOrdering>> {}; + template struct StrictWeakOrdering>: StrictWeakOrdering>> {}; } }} diff --git a/src/Magnum/Math/Half.h b/src/Magnum/Math/Half.h index 077e9c043..8ebcd8a87 100644 --- a/src/Magnum/Math/Half.h +++ b/src/Magnum/Math/Half.h @@ -162,11 +162,14 @@ Prints the value with 4 significant digits. MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utility::Debug& debug, Half value); namespace Implementation { -template <> struct StrictWeakOrdering { + +template<> struct StrictWeakOrdering { bool operator()(Half a, Half b) const { - return a.data() < b.data(); // Not mathematically equivalent to <, but does order + /* Not mathematically equivalent to <, but does order */ + return a.data() < b.data(); } }; + } }} diff --git a/src/Magnum/Math/Math.h b/src/Magnum/Math/Math.h index 307e41d63..5af08c63e 100644 --- a/src/Magnum/Math/Math.h +++ b/src/Magnum/Math/Math.h @@ -103,7 +103,7 @@ template class Range2D; template class Range3D; namespace Implementation { -template struct StrictWeakOrdering; + template struct StrictWeakOrdering; } #endif diff --git a/src/Magnum/Math/Matrix.h b/src/Magnum/Math/Matrix.h index df9d478a5..552d38016 100644 --- a/src/Magnum/Math/Matrix.h +++ b/src/Magnum/Math/Matrix.h @@ -321,7 +321,7 @@ template struct MatrixDeterminant<1, T> { } }; -template struct StrictWeakOrdering>: public StrictWeakOrdering> {}; +template struct StrictWeakOrdering>: StrictWeakOrdering> {}; } #endif diff --git a/src/Magnum/Math/Matrix3.h b/src/Magnum/Math/Matrix3.h index 9fae67e71..844537668 100644 --- a/src/Magnum/Math/Matrix3.h +++ b/src/Magnum/Math/Matrix3.h @@ -692,9 +692,8 @@ template inline Matrix3 Matrix3::invertedRigid() const { return from(inverseRotation, inverseRotation*-translation()); } -/* Specialization of helper types*/ namespace Implementation { -template struct StrictWeakOrdering>: public StrictWeakOrdering> {}; + template struct StrictWeakOrdering>: StrictWeakOrdering> {}; } }} diff --git a/src/Magnum/Math/Matrix4.h b/src/Magnum/Math/Matrix4.h index 4b0bc90ba..432ab5e3a 100644 --- a/src/Magnum/Math/Matrix4.h +++ b/src/Magnum/Math/Matrix4.h @@ -1024,9 +1024,8 @@ template Matrix4 Matrix4::invertedRigid() const { return from(inverseRotation, inverseRotation*-translation()); } -/* Specialization of helper types*/ namespace Implementation { -template struct StrictWeakOrdering>: public StrictWeakOrdering> {}; + template struct StrictWeakOrdering>: StrictWeakOrdering> {}; } }} diff --git a/src/Magnum/Math/Quaternion.h b/src/Magnum/Math/Quaternion.h index be8e4e051..ffa9eff72 100644 --- a/src/Magnum/Math/Quaternion.h +++ b/src/Magnum/Math/Quaternion.h @@ -739,8 +739,8 @@ template inline Vector3 Quaternion::transformVectorNormalized(con return vector + _scalar*t + Math::cross(_vector, t); } -/* Specialization of helper types*/ namespace Implementation { + template struct StrictWeakOrdering> { bool operator()(const Quaternion& a, const Quaternion& b) const { StrictWeakOrdering> o; @@ -752,6 +752,7 @@ template struct StrictWeakOrdering> { return a.scalar() < b.scalar(); } }; + } }} diff --git a/src/Magnum/Math/Range.h b/src/Magnum/Math/Range.h index 12e61c699..6756bf215 100644 --- a/src/Magnum/Math/Range.h +++ b/src/Magnum/Math/Range.h @@ -760,6 +760,7 @@ extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utili #endif namespace Implementation { + template struct StrictWeakOrdering> { bool operator()(const Range& a, const Range& b) const { StrictWeakOrdering::VectorType> o; @@ -770,6 +771,7 @@ template struct StrictWeakOrdering template struct StrictWeakOrdering> { bool operator()(const RectangularMatrix& a, const RectangularMatrix& b) const { StrictWeakOrdering> o; @@ -772,9 +772,10 @@ template struct StrictWeakOrdering< return false; } - return false; // a and b are equivalent + return false; /* a and b are equivalent */ } }; + } }} diff --git a/src/Magnum/Math/StrictWeakOrdering.h b/src/Magnum/Math/StrictWeakOrdering.h index 6cbe661bc..df4d0153b 100644 --- a/src/Magnum/Math/StrictWeakOrdering.h +++ b/src/Magnum/Math/StrictWeakOrdering.h @@ -32,11 +32,13 @@ namespace Magnum { namespace Math { namespace Implementation { -template struct StrictWeakOrdering { // Specialized for supported types + +template struct StrictWeakOrdering { /* Specialized for supported types */ bool operator()(const T& a, const T& b) const { return a < b; } }; + } /** @@ -63,11 +65,11 @@ struct StrictWeakOrdering { * * For scalar types this is equivalent to operator < */ - template bool operator()(const T& a, const T& b) const { - // Instantiate a specialization of Implementation::StrictWeakOrdering - // If users want to enable this for their own types, they must create - // a specialization of Magnum::Math::Implementation::StrictWeakOrdering - // for them. + template bool operator()(const T& a, const T& b) const { + /* Instantiate a specialization of Implementation::StrictWeakOrdering. + If users want to enable this for their own types, they must create + a specialization of Magnum::Math::Implementation::StrictWeakOrdering + for them. */ Implementation::StrictWeakOrdering o; return o(a, b); } diff --git a/src/Magnum/Math/Test/StrictWeakOrderingTest.cpp b/src/Magnum/Math/Test/StrictWeakOrderingTest.cpp index 9d5eb6ccb..be58e6f19 100644 --- a/src/Magnum/Math/Test/StrictWeakOrderingTest.cpp +++ b/src/Magnum/Math/Test/StrictWeakOrderingTest.cpp @@ -26,26 +26,19 @@ #include #include #include -#include #include "Magnum/Math/Vector2.h" #include "Magnum/Math/StrictWeakOrdering.h" -namespace std -{ - template <> struct less> - : public Magnum::Math::Implementation::StrictWeakOrdering> - {}; +namespace std { + template<> struct less>: public Magnum::Math::Implementation::StrictWeakOrdering> {}; } -namespace Magnum { -namespace Math { - -namespace Test { +namespace Magnum { namespace Math { namespace Test { using Vector2 = Magnum::Math::Vector2; -struct StrictWeakOrderingTest : Corrade::TestSuite::Tester { +struct StrictWeakOrderingTest: Corrade::TestSuite::Tester { explicit StrictWeakOrderingTest(); void base(); @@ -57,11 +50,10 @@ struct StrictWeakOrderingTest : Corrade::TestSuite::Tester { void map(); void mapShort(); void mapLess(); - }; StrictWeakOrderingTest::StrictWeakOrderingTest() { - addTests({ &StrictWeakOrderingTest::base, + addTests({&StrictWeakOrderingTest::base, &StrictWeakOrderingTest::set, &StrictWeakOrderingTest::setShort, @@ -171,8 +163,6 @@ void StrictWeakOrderingTest::mapLess() { CORRADE_VERIFY(m.begin()->second == 99); } -} -} -} +}}} CORRADE_TEST_MAIN(Magnum::Math::Test::StrictWeakOrderingTest) diff --git a/src/Magnum/Math/Vector.h b/src/Magnum/Math/Vector.h index 0a98ba2ca..8a0528d86 100644 --- a/src/Magnum/Math/Vector.h +++ b/src/Magnum/Math/Vector.h @@ -1413,8 +1413,8 @@ template inline std::pair Vector::minm return {min, max}; } -/* Specialization of helper types*/ namespace Implementation { + template struct StrictWeakOrdering> { bool operator()(const Vector& a, const Vector& b) const { for(std::size_t i = 0; i < size; ++i) { @@ -1424,9 +1424,10 @@ template struct StrictWeakOrdering> { return false; } - return false; // a and b are equivalent + return false; /* a and b are equivalent */ } }; + } }} diff --git a/src/Magnum/Math/Vector2.h b/src/Magnum/Math/Vector2.h index c09b2d2ce..1f03c0c44 100644 --- a/src/Magnum/Math/Vector2.h +++ b/src/Magnum/Math/Vector2.h @@ -191,7 +191,7 @@ namespace Implementation { template struct TypeForSize; template struct TypeForSize<2, T> { typedef Math::Vector2 Type; }; - template struct StrictWeakOrdering>: public StrictWeakOrdering> {}; + template struct StrictWeakOrdering>: StrictWeakOrdering> {}; } }} diff --git a/src/Magnum/Math/Vector3.h b/src/Magnum/Math/Vector3.h index 03da92c70..e2919f159 100644 --- a/src/Magnum/Math/Vector3.h +++ b/src/Magnum/Math/Vector3.h @@ -246,7 +246,7 @@ MAGNUM_VECTORn_OPERATOR_IMPLEMENTATION(3, Vector3) namespace Implementation { template struct TypeForSize<3, T> { typedef Math::Vector3 Type; }; - template struct StrictWeakOrdering>: public StrictWeakOrdering> {}; + template struct StrictWeakOrdering>: StrictWeakOrdering> {}; } }} diff --git a/src/Magnum/Math/Vector4.h b/src/Magnum/Math/Vector4.h index 92c81ed16..70c446793 100644 --- a/src/Magnum/Math/Vector4.h +++ b/src/Magnum/Math/Vector4.h @@ -255,7 +255,7 @@ MAGNUM_VECTORn_OPERATOR_IMPLEMENTATION(4, Vector4) namespace Implementation { template struct TypeForSize<4, T> { typedef Math::Vector4 Type; }; - template struct StrictWeakOrdering>: public StrictWeakOrdering> {}; + template struct StrictWeakOrdering>: StrictWeakOrdering> {}; } }}