diff --git a/src/Magnum/Array.h b/src/Magnum/Array.h index f7cc78097..aef050f52 100644 --- a/src/Magnum/Array.h +++ b/src/Magnum/Array.h @@ -32,7 +32,7 @@ #include #include "Magnum/Magnum.h" -#include "Magnum/Math/BoolVector.h" /* for Math::Implementation::Sequence */ +#include "Magnum/Math/BoolVector.h" /* for Math::Implementation::repeat() */ namespace Magnum { @@ -77,7 +77,7 @@ template class Array { constexpr /*implicit*/ Array(T value); #else template::value && dimensions != 1, T>::type> - constexpr /*implicit*/ Array(U value): Array(typename Math::Implementation::GenerateSequence::Type(), value) {} + constexpr /*implicit*/ Array(U value): Array(std::make_index_sequence{}, value) {} #endif /** @brief Equality */ @@ -106,7 +106,7 @@ template class Array { private: /* Implementation for Array::Array(U) */ - template constexpr explicit Array(Math::Implementation::Sequence, T value): _data{Math::Implementation::repeat(value, sequence)...} {} + template constexpr explicit Array(std::index_sequence, T value): _data{Math::Implementation::repeat(value, sequence)...} {} T _data[dimensions]; }; diff --git a/src/Magnum/Math/Bezier.h b/src/Magnum/Math/Bezier.h index 4d3919021..13f39574e 100644 --- a/src/Magnum/Math/Bezier.h +++ b/src/Magnum/Math/Bezier.h @@ -72,7 +72,7 @@ template class Bezier { constexpr /*implicit*/ Bezier(ZeroInitT = ZeroInit) noexcept /** @todoc remove workaround when doxygen is sane */ #ifndef DOXYGEN_GENERATING_OUTPUT - : Bezier{typename Implementation::GenerateSequence::Type{}, ZeroInit} + : Bezier{std::make_index_sequence{}, ZeroInit} #endif {} @@ -80,7 +80,7 @@ template class Bezier { explicit Bezier(NoInitT) noexcept /** @todoc remove workaround when doxygen is sane */ #ifndef DOXYGEN_GENERATING_OUTPUT - : Bezier{typename Implementation::GenerateSequence::Type{}, NoInit} + : Bezier{std::make_index_sequence{}, NoInit} #endif {} @@ -95,7 +95,7 @@ template class Bezier { * Performs only default casting on the values, no rounding or * anything else. */ - template constexpr explicit Bezier(const Bezier& other) noexcept: Bezier{typename Implementation::GenerateSequence::Type(), other} {} + template constexpr explicit Bezier(const Bezier& other) noexcept: Bezier{std::make_index_sequence{}, other} {} /** @brief Construct Bézier from external representation */ template::from(std::declval()))> constexpr explicit Bezier(const U& other) noexcept: Bezier{Implementation::BezierConverter::from(other)} {} @@ -156,11 +156,11 @@ template class Bezier { private: /* Implementation for Bezier::Bezier(const Bezier&) */ - template constexpr explicit Bezier(Implementation::Sequence, const Bezier& other) noexcept: _data{Vector(other._data[sequence])...} {} + template constexpr explicit Bezier(std::index_sequence, const Bezier& other) noexcept: _data{Vector(other._data[sequence])...} {} /* Implementation for Bezier::Bezier(ZeroInitT) and Bezier::Bezier(NoInitT) */ /* MSVC 2015 can't handle {} here */ - template constexpr explicit Bezier(Implementation::Sequence, U): _data{Vector((static_cast(sequence), U{typename U::Init{}}))...} {} + template constexpr explicit Bezier(std::index_sequence, U): _data{Vector((static_cast(sequence), U{typename U::Init{}}))...} {} /* Calculates and returns all intermediate points generated when using De Casteljau's algorithm */ std::array, order + 1> calculateIntermediatePoints(Float t) const { diff --git a/src/Magnum/Math/BoolVector.h b/src/Magnum/Math/BoolVector.h index 63924981e..7ac33056d 100644 --- a/src/Magnum/Math/BoolVector.h +++ b/src/Magnum/Math/BoolVector.h @@ -29,6 +29,7 @@ * @brief Class @ref Magnum::Math::BoolVector */ +#include #include #include @@ -38,26 +39,6 @@ namespace Magnum { namespace Math { namespace Implementation { - /** @todo C++14: use std::make_index_sequence and std::integer_sequence */ - template struct Sequence {}; - - #ifndef DOXYGEN_GENERATING_OUTPUT - /* E.g. GenerateSequence<3>::Type is Sequence<0, 1, 2> */ - template struct GenerateSequence: - GenerateSequence {}; - - template struct GenerateSequence<0, sequence...> { - typedef Sequence Type; - }; - - template struct GenerateReverseSequence: - GenerateReverseSequence {}; - - template struct GenerateReverseSequence<0, sequence...> { - typedef Sequence Type; - }; - #endif - template constexpr T repeat(T value, std::size_t) { return value; } } @@ -100,7 +81,7 @@ template class BoolVector { #ifdef DOXYGEN_GENERATING_OUTPUT explicit BoolVector(T value) noexcept; #else - template::value && size != 1, bool>::type> constexpr explicit BoolVector(T value) noexcept: BoolVector(typename Implementation::GenerateSequence::Type(), value ? FullSegmentMask : 0) {} + template::value && size != 1, bool>::type> constexpr explicit BoolVector(T value) noexcept: BoolVector(std::make_index_sequence{}, value ? FullSegmentMask : 0) {} #endif /** @brief Copy constructor */ @@ -237,7 +218,7 @@ template class BoolVector { }; /* Implementation for Vector::Vector(U) */ - template constexpr explicit BoolVector(Implementation::Sequence, UnsignedByte value): _data{Implementation::repeat(value, sequence)...} {} + template constexpr explicit BoolVector(std::index_sequence, UnsignedByte value): _data{Implementation::repeat(value, sequence)...} {} UnsignedByte _data[(size-1)/8+1]; }; diff --git a/src/Magnum/Math/Matrix.h b/src/Magnum/Math/Matrix.h index 511224e31..1acc379ae 100644 --- a/src/Magnum/Math/Matrix.h +++ b/src/Magnum/Math/Matrix.h @@ -86,7 +86,7 @@ template class Matrix: public RectangularMatrix{typename Implementation::GenerateSequence::Type(), Vector(value)} + : RectangularMatrix{std::make_index_sequence{}, Vector(value)} #endif {} @@ -113,7 +113,7 @@ template class Matrix: public RectangularMatrix{typename Implementation::GenerateSequence::Type(), value} + : RectangularMatrix{std::make_index_sequence{}, value} #endif {} diff --git a/src/Magnum/Math/RectangularMatrix.h b/src/Magnum/Math/RectangularMatrix.h index 4881246ea..20152a1f0 100644 --- a/src/Magnum/Math/RectangularMatrix.h +++ b/src/Magnum/Math/RectangularMatrix.h @@ -104,14 +104,14 @@ template class RectangularMatrix { * @see @ref diagonal() */ constexpr static RectangularMatrix fromDiagonal(const Vector& diagonal) noexcept { - return RectangularMatrix(typename Implementation::GenerateSequence::Type(), diagonal); + return RectangularMatrix(std::make_index_sequence{}, diagonal); } /** @brief Construct zero-filled matrix */ constexpr /*implicit*/ RectangularMatrix(ZeroInitT = ZeroInit) noexcept /** @todoc remove workaround when doxygen is sane */ #ifndef DOXYGEN_GENERATING_OUTPUT - : RectangularMatrix{typename Implementation::GenerateSequence::Type{}, ZeroInit} + : RectangularMatrix{std::make_index_sequence{}, ZeroInit} #endif {} @@ -119,7 +119,7 @@ template class RectangularMatrix { explicit RectangularMatrix(NoInitT) noexcept /** @todoc remove workaround when doxygen is sane */ #ifndef DOXYGEN_GENERATING_OUTPUT - : RectangularMatrix{typename Implementation::GenerateSequence::Type{}, NoInit} + : RectangularMatrix{std::make_index_sequence{}, NoInit} #endif {} @@ -132,7 +132,7 @@ template class RectangularMatrix { constexpr explicit RectangularMatrix(T value) noexcept /** @todoc remove workaround when doxygen is sane */ #ifndef DOXYGEN_GENERATING_OUTPUT - : RectangularMatrix{typename Implementation::GenerateSequence::Type(), value} + : RectangularMatrix{std::make_index_sequence{}, value} #endif {} @@ -147,7 +147,7 @@ template class RectangularMatrix { * // integral == {1, 2, -15, 7} * @endcode */ - template constexpr explicit RectangularMatrix(const RectangularMatrix& other) noexcept: RectangularMatrix(typename Implementation::GenerateSequence::Type(), other) {} + template constexpr explicit RectangularMatrix(const RectangularMatrix& other) noexcept: RectangularMatrix(std::make_index_sequence{}, other) {} /** @brief Construct matrix from external representation */ template::from(std::declval()))> constexpr explicit RectangularMatrix(const U& other): RectangularMatrix(Implementation::RectangularMatrixConverter::from(other)) {} @@ -400,7 +400,7 @@ template class RectangularMatrix { * @see @ref transposed(), @ref flippedRows(), @ref Vector::flipped() */ constexpr RectangularMatrix flippedCols() const { - return flippedColsInternal(typename Implementation::GenerateReverseSequence::Type{}); + return flippedColsInternal(std::make_index_sequence{}); } /** @@ -410,7 +410,7 @@ template class RectangularMatrix { * @see @ref transposed(), @ref flippedCols(), @ref Vector::flipped() */ constexpr RectangularMatrix flippedRows() const { - return flippedRowsInternal(typename Implementation::GenerateSequence::Type{}); + return flippedRowsInternal(std::make_index_sequence{}); } /** @@ -439,29 +439,29 @@ template class RectangularMatrix { private: #endif /* Implementation for RectangularMatrix::fromDiagonal() and Matrix(IdentityInitT, T) */ - template constexpr explicit RectangularMatrix(Implementation::Sequence, const Vector& diagonal); + template constexpr explicit RectangularMatrix(std::index_sequence, const Vector& diagonal); /* Implementation for RectangularMatrix::RectangularMatrix(T) and Matrix(T) */ /* MSVC 2015 can't handle {} here */ - template constexpr explicit RectangularMatrix(Implementation::Sequence, T value) noexcept: _data{Vector((static_cast(sequence), value))...} {} + template constexpr explicit RectangularMatrix(std::index_sequence, T value) noexcept: _data{Vector((static_cast(sequence), value))...} {} private: /* Implementation for RectangularMatrix::RectangularMatrix(const RectangularMatrix&) */ - template constexpr explicit RectangularMatrix(Implementation::Sequence, const RectangularMatrix& matrix) noexcept: _data{Vector(matrix[sequence])...} {} + template constexpr explicit RectangularMatrix(std::index_sequence, const RectangularMatrix& matrix) noexcept: _data{Vector(matrix[sequence])...} {} /* Implementation for RectangularMatrix::RectangularMatrix(ZeroInitT) and RectangularMatrix::RectangularMatrix(NoInitT) */ /* MSVC 2015 can't handle {} here */ - template constexpr explicit RectangularMatrix(Implementation::Sequence, U) noexcept: _data{Vector((static_cast(sequence), U{typename U::Init{}}))...} {} + template constexpr explicit RectangularMatrix(std::index_sequence, U) noexcept: _data{Vector((static_cast(sequence), U{typename U::Init{}}))...} {} - template constexpr RectangularMatrix flippedColsInternal(Implementation::Sequence) const { - return {(*this)[sequence]...}; + template constexpr RectangularMatrix flippedColsInternal(std::index_sequence) const { + return {(*this)[cols - 1 - sequence]...}; } - template constexpr RectangularMatrix flippedRowsInternal(Implementation::Sequence) const { + template constexpr RectangularMatrix flippedRowsInternal(std::index_sequence) const { return {(*this)[sequence].flipped()...}; } - template constexpr Vector diagonalInternal(Implementation::Sequence) const; + template constexpr Vector diagonalInternal(std::index_sequence) const; Vector _data[cols]; }; @@ -694,15 +694,15 @@ extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utili #endif namespace Implementation { - template constexpr Vector diagonalMatrixColumn2(Implementation::Sequence, const T& number) { + template constexpr Vector diagonalMatrixColumn2(std::index_sequence, const T& number) { return {(sequence == i ? number : T(0))...}; } template constexpr Vector diagonalMatrixColumn(const T& number) { - return diagonalMatrixColumn2(typename Implementation::GenerateSequence::Type(), number); + return diagonalMatrixColumn2(std::make_index_sequence{}, number); } } -template template constexpr RectangularMatrix::RectangularMatrix(Implementation::Sequence, const Vector& diagonal): _data{Implementation::diagonalMatrixColumn(sequence < DiagonalSize ? diagonal[sequence] : T{})...} {} +template template constexpr RectangularMatrix::RectangularMatrix(std::index_sequence, const Vector& diagonal): _data{Implementation::diagonalMatrixColumn(sequence < DiagonalSize ? diagonal[sequence] : T{})...} {} template inline Vector RectangularMatrix::row(std::size_t row) const { Vector out; @@ -748,10 +748,10 @@ template inline RectangularMatrix constexpr auto RectangularMatrix::diagonal() const -> Vector { return diagonalInternal(typename Implementation::GenerateSequence::Type()); } +template constexpr auto RectangularMatrix::diagonal() const -> Vector { return diagonalInternal(std::make_index_sequence{}); } #ifndef DOXYGEN_GENERATING_OUTPUT -template template constexpr auto RectangularMatrix::diagonalInternal(Implementation::Sequence) const -> Vector { +template template constexpr auto RectangularMatrix::diagonalInternal(std::index_sequence) const -> Vector { return {(*this)[sequence][sequence]...}; } #endif diff --git a/src/Magnum/Math/Vector.h b/src/Magnum/Math/Vector.h index 0f17e44f5..678b871ce 100644 --- a/src/Magnum/Math/Vector.h +++ b/src/Magnum/Math/Vector.h @@ -145,7 +145,7 @@ template class Vector { * @see @ref Vector4::pad(const Vector&, T, T) */ template constexpr static Vector pad(const Vector& a, T value = T(0)) { - return padInternal(typename Implementation::GenerateSequence::Type(), a, value); + return padInternal(std::make_index_sequence{}, a, value); } #ifdef MAGNUM_BUILD_DEPRECATED @@ -191,7 +191,7 @@ template class Vector { #ifdef DOXYGEN_GENERATING_OUTPUT constexpr explicit Vector(T value) noexcept; #else - template::value && size != 1, T>::type> constexpr explicit Vector(U value) noexcept: Vector(typename Implementation::GenerateSequence::Type(), value) {} + template::value && size != 1, T>::type> constexpr explicit Vector(U value) noexcept: Vector(std::make_index_sequence{}, value) {} #endif /** @@ -205,7 +205,7 @@ template class Vector { * // integral == {1, 2, -15, 7} * @endcode */ - template constexpr explicit Vector(const Vector& other) noexcept: Vector(typename Implementation::GenerateSequence::Type(), other) {} + template constexpr explicit Vector(const Vector& other) noexcept: Vector(std::make_index_sequence{}, other) {} /** @brief Construct vector from external representation */ template::from(std::declval()))> constexpr explicit Vector(const U& other) noexcept: Vector(Implementation::VectorConverter::from(other)) {} @@ -537,7 +537,7 @@ template class Vector { * @ref RectangularMatrix::flippedRows() */ constexpr Vector flipped() const { - return flippedInternal(typename Implementation::GenerateReverseSequence::Type{}); + return flippedInternal(std::make_index_sequence{}); } /** @@ -577,17 +577,17 @@ template class Vector { private: /* Implementation for Vector::Vector(const Vector&) */ - template constexpr explicit Vector(Implementation::Sequence, const Vector& vector) noexcept: _data{T(vector._data[sequence])...} {} + template constexpr explicit Vector(std::index_sequence, const Vector& vector) noexcept: _data{T(vector._data[sequence])...} {} /* Implementation for Vector::Vector(U) */ - template constexpr explicit Vector(Implementation::Sequence, T value) noexcept: _data{Implementation::repeat(value, sequence)...} {} + template constexpr explicit Vector(std::index_sequence, T value) noexcept: _data{Implementation::repeat(value, sequence)...} {} - template constexpr static Vector padInternal(Implementation::Sequence, const Vector& a, T value) { + template constexpr static Vector padInternal(std::index_sequence, const Vector& a, T value) { return {sequence < otherSize ? a[sequence] : value...}; } - template constexpr Vector flippedInternal(Implementation::Sequence) const { - return {(*this)[sequence]...}; + template constexpr Vector flippedInternal(std::index_sequence) const { + return {(*this)[size - 1 - sequence]...}; } T _data[size];