Browse Source

Switch to the new & optimized GenerateSequence from Corrade.

This should help slightly with compiler memory usage, on GCC 10 the huge
Trade::MaterialData test used "only" 309 instead of 318 MB after this
change.
pull/491/head
Vladimír Vondruš 5 years ago
parent
commit
5a1f43f20b
  1. 11
      src/Magnum/Array.h
  2. 12
      src/Magnum/Math/Bezier.h
  3. 18
      src/Magnum/Math/BoolVector.h
  4. 14
      src/Magnum/Math/Matrix.h
  5. 40
      src/Magnum/Math/RectangularMatrix.h
  6. 4
      src/Magnum/Math/Swizzle.h
  7. 16
      src/Magnum/Math/Vector.h
  8. 8
      src/Magnum/Trade/MaterialData.h

11
src/Magnum/Array.h

@ -30,12 +30,17 @@
*/
#include <type_traits>
#include <Corrade/Containers/sequenceHelpers.h>
#include <Corrade/Utility/Debug.h>
#include "Magnum/Magnum.h"
#include "Magnum/Math/BoolVector.h" /* for Math::Implementation::Sequence */
namespace Magnum {
namespace Implementation {
template<class T> constexpr T repeat(T value, std::size_t) { return value; }
}
/**
@brief Array
@tparam dimensions Dimension count
@ -77,7 +82,7 @@ template<UnsignedInt dimensions, class T> class Array {
constexpr /*implicit*/ Array(T value);
#else
template<class U, class V = typename std::enable_if<std::is_same<T, U>::value && dimensions != 1, T>::type>
constexpr /*implicit*/ Array(U value): Array(typename Math::Implementation::GenerateSequence<dimensions>::Type(), value) {}
constexpr /*implicit*/ Array(U value): Array(typename Containers::Implementation::GenerateSequence<dimensions>::Type{}, value) {}
#endif
/** @brief Equality */
@ -112,7 +117,7 @@ template<UnsignedInt dimensions, class T> class Array {
private:
/* Implementation for Array<dimensions, T>::Array(U) */
template<std::size_t ...sequence> constexpr explicit Array(Math::Implementation::Sequence<sequence...>, T value): _data{Math::Implementation::repeat(value, sequence)...} {}
template<std::size_t ...sequence> constexpr explicit Array(Containers::Implementation::Sequence<sequence...>, T value): _data{Implementation::repeat(value, sequence)...} {}
};
/**

12
src/Magnum/Math/Bezier.h

@ -102,17 +102,17 @@ template<UnsignedInt order, UnsignedInt dimensions, class T> class Bezier {
*
* Equivalent to @ref Bezier(ZeroInitT).
*/
constexpr /*implicit*/ Bezier() noexcept: Bezier<order, dimensions, T>{typename Implementation::GenerateSequence<order + 1>::Type{}, ZeroInit} {}
constexpr /*implicit*/ Bezier() noexcept: Bezier<order, dimensions, T>{typename Corrade::Containers::Implementation::GenerateSequence<order + 1>::Type{}, ZeroInit} {}
/**
* @brief Construct a zero curve
*
* All control points are zero vectors.
*/
constexpr explicit Bezier(ZeroInitT) noexcept: Bezier<order, dimensions, T>{typename Implementation::GenerateSequence<order + 1>::Type{}, ZeroInit} {}
constexpr explicit Bezier(ZeroInitT) noexcept: Bezier<order, dimensions, T>{typename Corrade::Containers::Implementation::GenerateSequence<order + 1>::Type{}, ZeroInit} {}
/** @brief Construct Bézier without initializing the contents */
explicit Bezier(Magnum::NoInitT) noexcept: Bezier<order, dimensions, T>{typename Implementation::GenerateSequence<order + 1>::Type{}, Magnum::NoInit} {}
explicit Bezier(Magnum::NoInitT) noexcept: Bezier<order, dimensions, T>{typename Corrade::Containers::Implementation::GenerateSequence<order + 1>::Type{}, Magnum::NoInit} {}
/** @brief Construct Bézier curve with given array of control points */
template<typename... U> constexpr /*implicit*/ Bezier(const Vector<dimensions, T>& first, U... next) noexcept: _data{first, next...} {
@ -125,7 +125,7 @@ template<UnsignedInt order, UnsignedInt dimensions, class T> class Bezier {
* Performs only default casting on the values, no rounding or
* anything else.
*/
template<class U> constexpr explicit Bezier(const Bezier<order, dimensions, U>& other) noexcept: Bezier{typename Implementation::GenerateSequence<order + 1>::Type(), other} {}
template<class U> constexpr explicit Bezier(const Bezier<order, dimensions, U>& other) noexcept: Bezier{typename Corrade::Containers::Implementation::GenerateSequence<order + 1>::Type{}, other} {}
/** @brief Construct Bézier curve from external representation */
template<class U, class V = decltype(Implementation::BezierConverter<order, dimensions, T, U>::from(std::declval<U>()))> constexpr explicit Bezier(const U& other) noexcept: Bezier<order, dimensions, T>{Implementation::BezierConverter<order, dimensions, T, U>::from(other)} {}
@ -198,11 +198,11 @@ template<UnsignedInt order, UnsignedInt dimensions, class T> class Bezier {
private:
/* Implementation for Bezier<order, dimensions, T>::Bezier(const Bezier<order, dimensions, U>&) */
template<class U, std::size_t ...sequence> constexpr explicit Bezier(Implementation::Sequence<sequence...>, const Bezier<order, dimensions, U>& other) noexcept: _data{Vector<dimensions, T>(other._data[sequence])...} {}
template<class U, std::size_t ...sequence> constexpr explicit Bezier(Corrade::Containers::Implementation::Sequence<sequence...>, const Bezier<order, dimensions, U>& other) noexcept: _data{Vector<dimensions, T>(other._data[sequence])...} {}
/* Implementation for Bezier<order, dimensions, T>::Bezier(ZeroInitT) and Bezier<order, dimensions, T>::Bezier(NoInitT) */
/* MSVC 2015 can't handle {} here */
template<class U, std::size_t ...sequence> constexpr explicit Bezier(Implementation::Sequence<sequence...>, U): _data{Vector<dimensions, T>((static_cast<void>(sequence), U{typename U::Init{}}))...} {}
template<class U, std::size_t ...sequence> constexpr explicit Bezier(Corrade::Containers::Implementation::Sequence<sequence...>, U): _data{Vector<dimensions, T>((static_cast<void>(sequence), U{typename U::Init{}}))...} {}
/* Calculates and returns all intermediate points generated when using De Casteljau's algorithm */
void calculateIntermediatePoints(Bezier<order, dimensions, T>(&iPoints)[order + 1], Float t) const {

18
src/Magnum/Math/BoolVector.h

@ -30,6 +30,7 @@
*/
#include <type_traits>
#include <Corrade/Containers/sequenceHelpers.h>
#ifndef CORRADE_NO_DEBUG
#include <Corrade/Utility/Debug.h>
#endif
@ -43,19 +44,6 @@ namespace Magnum { namespace Math {
namespace Implementation {
template<std::size_t, class> struct BoolVectorConverter;
/** @todo C++14: use std::make_index_sequence and std::integer_sequence */
template<std::size_t ...> struct Sequence {};
#ifndef DOXYGEN_GENERATING_OUTPUT
/* E.g. GenerateSequence<3>::Type is Sequence<0, 1, 2> */
template<std::size_t N, std::size_t ...sequence> struct GenerateSequence:
GenerateSequence<N-1, N-1, sequence...> {};
template<std::size_t ...sequence> struct GenerateSequence<0, sequence...> {
typedef Sequence<sequence...> Type;
};
#endif
template<class T> constexpr T repeat(T value, std::size_t) { return value; }
}
@ -129,7 +117,7 @@ template<std::size_t size> class BoolVector {
#ifdef DOXYGEN_GENERATING_OUTPUT
explicit BoolVector(T value) noexcept;
#else
template<class T, class U = typename std::enable_if<std::is_same<bool, T>::value && size != 1, bool>::type> constexpr explicit BoolVector(T value) noexcept: BoolVector(typename Implementation::GenerateSequence<DataSize>::Type(), value ? FullSegmentMask : 0) {}
template<class T, class U = typename std::enable_if<std::is_same<bool, T>::value && size != 1, bool>::type> constexpr explicit BoolVector(T value) noexcept: BoolVector(typename Corrade::Containers::Implementation::GenerateSequence<DataSize>::Type{}, value ? FullSegmentMask : 0) {}
#endif
/** @brief Construct a boolean vector from external representation */
@ -305,7 +293,7 @@ template<std::size_t size> class BoolVector {
};
/* Implementation for Vector<size, T>::Vector(U) */
template<std::size_t ...sequence> constexpr explicit BoolVector(Implementation::Sequence<sequence...>, UnsignedByte value): _data{Implementation::repeat(value, sequence)...} {}
template<std::size_t ...sequence> constexpr explicit BoolVector(Corrade::Containers::Implementation::Sequence<sequence...>, UnsignedByte value): _data{Implementation::repeat(value, sequence)...} {}
UnsignedByte _data[(size-1)/8+1];
};

14
src/Magnum/Math/Matrix.h

@ -36,13 +36,13 @@ namespace Magnum { namespace Math {
namespace Implementation {
template<std::size_t, class> struct MatrixDeterminant;
template<std::size_t size, std::size_t col, std::size_t otherSize, class T, std::size_t ...row> constexpr Vector<size, T> valueOrIdentityVector(Sequence<row...>, const RectangularMatrix<otherSize, otherSize, T>& other) {
template<std::size_t size, std::size_t col, std::size_t otherSize, class T, std::size_t ...row> constexpr Vector<size, T> valueOrIdentityVector(Corrade::Containers::Implementation::Sequence<row...>, const RectangularMatrix<otherSize, otherSize, T>& other) {
return {(col < otherSize && row < otherSize ? other[col][row] :
col == row ? T{1} : T{0})...};
}
template<std::size_t size, std::size_t col, std::size_t otherSize, class T> constexpr Vector<size, T> valueOrIdentityVector(const RectangularMatrix<otherSize, otherSize, T>& other) {
return valueOrIdentityVector<size, col>(typename Implementation::GenerateSequence<size>::Type(), other);
return valueOrIdentityVector<size, col>(typename Corrade::Containers::Implementation::GenerateSequence<size>::Type{}, other);
}
}
@ -72,7 +72,7 @@ template<std::size_t size, class T> class Matrix: public RectangularMatrix<size,
*
* Equivalent to @ref Matrix(IdentityInitT, T).
*/
constexpr /*implicit*/ Matrix() noexcept: RectangularMatrix<size, size, T>{typename Implementation::GenerateSequence<size>::Type(), Vector<size, T>(T(1))} {}
constexpr /*implicit*/ Matrix() noexcept: RectangularMatrix<size, size, T>{typename Corrade::Containers::Implementation::GenerateSequence<size>::Type{}, Vector<size, T>(T(1))} {}
/**
* @brief Construct an identity matrix
@ -80,7 +80,7 @@ template<std::size_t size, class T> class Matrix: public RectangularMatrix<size,
* The @p value allows you to specify a value on diagonal.
* @see @ref fromDiagonal()
*/
constexpr explicit Matrix(IdentityInitT, T value = T(1)) noexcept: RectangularMatrix<size, size, T>{typename Implementation::GenerateSequence<size>::Type(), Vector<size, T>(value)} {}
constexpr explicit Matrix(IdentityInitT, T value = T(1)) noexcept: RectangularMatrix<size, size, T>{typename Corrade::Containers::Implementation::GenerateSequence<size>::Type{}, Vector<size, T>(value)} {}
/** @copydoc RectangularMatrix::RectangularMatrix(ZeroInitT) */
constexpr explicit Matrix(ZeroInitT) noexcept: RectangularMatrix<size, size, T>{ZeroInit} {}
@ -92,7 +92,7 @@ template<std::size_t size, class T> class Matrix: public RectangularMatrix<size,
template<class ...U> constexpr /*implicit*/ Matrix(const Vector<size, T>& first, const U&... next) noexcept: RectangularMatrix<size, size, T>(first, next...) {}
/** @brief Construct with one value for all elements */
constexpr explicit Matrix(T value) noexcept: RectangularMatrix<size, size, T>{typename Implementation::GenerateSequence<size>::Type(), value} {}
constexpr explicit Matrix(T value) noexcept: RectangularMatrix<size, size, T>{typename Corrade::Containers::Implementation::GenerateSequence<size>::Type{}, value} {}
/**
* @brief Construct from a matrix of adifferent type
@ -114,7 +114,7 @@ template<std::size_t size, class T> class Matrix: public RectangularMatrix<size,
* columns and rows from it; if the other matrix is smaller, it's
* expanded to an identity (ones on diagonal, zeros elsewhere).
*/
template<std::size_t otherSize> constexpr explicit Matrix(const RectangularMatrix<otherSize, otherSize, T>& other) noexcept: Matrix<size, T>{typename Implementation::GenerateSequence<size>::Type(), other} {}
template<std::size_t otherSize> constexpr explicit Matrix(const RectangularMatrix<otherSize, otherSize, T>& other) noexcept: Matrix<size, T>{typename Corrade::Containers::Implementation::GenerateSequence<size>::Type{}, other} {}
/** @brief Copy constructor */
constexpr /*implicit*/ Matrix(const RectangularMatrix<size, size, T>& other) noexcept: RectangularMatrix<size, size, T>(other) {}
@ -302,7 +302,7 @@ template<std::size_t size, class T> class Matrix: public RectangularMatrix<size,
friend struct Implementation::MatrixDeterminant<size, T>;
/* Implementation for RectangularMatrix<cols, rows, T>::RectangularMatrix(const RectangularMatrix<cols, rows, U>&) */
template<std::size_t otherSize, std::size_t ...col> constexpr explicit Matrix(Implementation::Sequence<col...>, const RectangularMatrix<otherSize, otherSize, T>& other) noexcept: RectangularMatrix<size, size, T>{Implementation::valueOrIdentityVector<size, col>(other)...} {}
template<std::size_t otherSize, std::size_t ...col> constexpr explicit Matrix(Corrade::Containers::Implementation::Sequence<col...>, const RectangularMatrix<otherSize, otherSize, T>& other) noexcept: RectangularMatrix<size, size, T>{Implementation::valueOrIdentityVector<size, col>(other)...} {}
};
/**

40
src/Magnum/Math/RectangularMatrix.h

@ -114,7 +114,7 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
* @see @ref diagonal()
*/
constexpr static RectangularMatrix<cols, rows, T> fromDiagonal(const Vector<DiagonalSize, T>& diagonal) noexcept {
return RectangularMatrix(typename Implementation::GenerateSequence<cols>::Type(), diagonal);
return RectangularMatrix(typename Corrade::Containers::Implementation::GenerateSequence<cols>::Type{}, diagonal);
}
/**
@ -122,13 +122,13 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
*
* Equivalent to @ref RectangularMatrix(ZeroInitT).
*/
constexpr /*implicit*/ RectangularMatrix() noexcept: RectangularMatrix<cols, rows, T>{typename Implementation::GenerateSequence<cols>::Type{}, ZeroInit} {}
constexpr /*implicit*/ RectangularMatrix() noexcept: RectangularMatrix<cols, rows, T>{typename Corrade::Containers::Implementation::GenerateSequence<cols>::Type{}, ZeroInit} {}
/** @brief Construct a zero-filled matrix */
constexpr explicit RectangularMatrix(ZeroInitT) noexcept: RectangularMatrix<cols, rows, T>{typename Implementation::GenerateSequence<cols>::Type{}, ZeroInit} {}
constexpr explicit RectangularMatrix(ZeroInitT) noexcept: RectangularMatrix<cols, rows, T>{typename Corrade::Containers::Implementation::GenerateSequence<cols>::Type{}, ZeroInit} {}
/** @brief Construct without initializing the contents */
explicit RectangularMatrix(Magnum::NoInitT) noexcept: RectangularMatrix<cols, rows, T>{typename Implementation::GenerateSequence<cols>::Type{}, Magnum::NoInit} {}
explicit RectangularMatrix(Magnum::NoInitT) noexcept: RectangularMatrix<cols, rows, T>{typename Corrade::Containers::Implementation::GenerateSequence<cols>::Type{}, Magnum::NoInit} {}
/** @brief Construct from column vectors */
template<class ...U> constexpr /*implicit*/ RectangularMatrix(const Vector<rows, T>& first, const U&... next) noexcept: _data{first, next...} {
@ -136,7 +136,7 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
}
/** @brief Construct with one value for all components */
constexpr explicit RectangularMatrix(T value) noexcept: RectangularMatrix{typename Implementation::GenerateSequence<cols>::Type(), value} {}
constexpr explicit RectangularMatrix(T value) noexcept: RectangularMatrix{typename Corrade::Containers::Implementation::GenerateSequence<cols>::Type{}, value} {}
/**
* @brief Construct matrix from another of different type
@ -146,7 +146,7 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
*
* @snippet MagnumMath.cpp RectangularMatrix-conversion
*/
template<class U> constexpr explicit RectangularMatrix(const RectangularMatrix<cols, rows, U>& other) noexcept: RectangularMatrix(typename Implementation::GenerateSequence<cols>::Type(), other) {}
template<class U> constexpr explicit RectangularMatrix(const RectangularMatrix<cols, rows, U>& other) noexcept: RectangularMatrix(typename Corrade::Containers::Implementation::GenerateSequence<cols>::Type{}, other) {}
/** @brief Construct matrix from external representation */
template<class U, class V = decltype(Implementation::RectangularMatrixConverter<cols, rows, T, U>::from(std::declval<U>()))> constexpr explicit RectangularMatrix(const U& other): RectangularMatrix(Implementation::RectangularMatrixConverter<cols, rows, T, U>::from(other)) {}
@ -399,7 +399,7 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
* @see @ref transposed(), @ref flippedRows(), @ref Vector::flipped()
*/
constexpr RectangularMatrix<cols, rows, T> flippedCols() const {
return flippedColsInternal(typename Implementation::GenerateSequence<cols>::Type{});
return flippedColsInternal(typename Corrade::Containers::Implementation::GenerateSequence<cols>::Type{});
}
/**
@ -409,7 +409,7 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
* @see @ref transposed(), @ref flippedCols(), @ref Vector::flipped()
*/
constexpr RectangularMatrix<cols, rows, T> flippedRows() const {
return flippedRowsInternal(typename Implementation::GenerateSequence<cols>::Type{});
return flippedRowsInternal(typename Corrade::Containers::Implementation::GenerateSequence<cols>::Type{});
}
/**
@ -421,7 +421,7 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
/* NVCC (from CUDA) has problems compiling this function under
Windows when there's a separate definition due to DiagonalSize
(see https://github.com/mosra/magnum/issues/345 for details) */
return diagonalInternal(typename Implementation::GenerateSequence<DiagonalSize>::Type());
return diagonalInternal(typename Corrade::Containers::Implementation::GenerateSequence<DiagonalSize>::Type{});
}
/**
@ -443,11 +443,11 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
private:
#endif
/* Implementation for RectangularMatrix<cols, rows, T>::fromDiagonal() and Matrix<size, T>(IdentityInitT, T) */
template<std::size_t ...sequence> constexpr explicit RectangularMatrix(Implementation::Sequence<sequence...>, const Vector<DiagonalSize, T>& diagonal);
template<std::size_t ...sequence> constexpr explicit RectangularMatrix(Corrade::Containers::Implementation::Sequence<sequence...>, const Vector<DiagonalSize, T>& diagonal);
/* Implementation for RectangularMatrix<cols, rows, T>::RectangularMatrix(T) and Matrix<size, T>(T) */
/* MSVC 2015 can't handle {} here */
template<std::size_t ...sequence> constexpr explicit RectangularMatrix(Implementation::Sequence<sequence...>, T value) noexcept: _data{Vector<rows, T>((static_cast<void>(sequence), value))...} {}
template<std::size_t ...sequence> constexpr explicit RectangularMatrix(Corrade::Containers::Implementation::Sequence<sequence...>, T value) noexcept: _data{Vector<rows, T>((static_cast<void>(sequence), value))...} {}
private:
/* These two needed to access _data to speed up debug builds,
@ -456,21 +456,21 @@ template<std::size_t cols, std::size_t rows, class T> class RectangularMatrix {
template<std::size_t, class> friend struct Implementation::MatrixDeterminant;
/* Implementation for RectangularMatrix<cols, rows, T>::RectangularMatrix(const RectangularMatrix<cols, rows, U>&) */
template<class U, std::size_t ...sequence> constexpr explicit RectangularMatrix(Implementation::Sequence<sequence...>, const RectangularMatrix<cols, rows, U>& matrix) noexcept: _data{Vector<rows, T>(matrix[sequence])...} {}
template<class U, std::size_t ...sequence> constexpr explicit RectangularMatrix(Corrade::Containers::Implementation::Sequence<sequence...>, const RectangularMatrix<cols, rows, U>& matrix) noexcept: _data{Vector<rows, T>(matrix[sequence])...} {}
/* Implementation for RectangularMatrix<cols, rows, T>::RectangularMatrix(ZeroInitT) and RectangularMatrix<cols, rows, T>::RectangularMatrix(NoInitT) */
/* MSVC 2015 can't handle {} here */
template<class U, std::size_t ...sequence> constexpr explicit RectangularMatrix(Implementation::Sequence<sequence...>, U) noexcept: _data{Vector<rows, T>((static_cast<void>(sequence), U{typename U::Init{}}))...} {}
template<class U, std::size_t ...sequence> constexpr explicit RectangularMatrix(Corrade::Containers::Implementation::Sequence<sequence...>, U) noexcept: _data{Vector<rows, T>((static_cast<void>(sequence), U{typename U::Init{}}))...} {}
template<std::size_t ...sequence> constexpr RectangularMatrix<cols, rows, T> flippedColsInternal(Implementation::Sequence<sequence...>) const {
template<std::size_t ...sequence> constexpr RectangularMatrix<cols, rows, T> flippedColsInternal(Corrade::Containers::Implementation::Sequence<sequence...>) const {
return {_data[cols - 1 - sequence]...};
}
template<std::size_t ...sequence> constexpr RectangularMatrix<cols, rows, T> flippedRowsInternal(Implementation::Sequence<sequence...>) const {
template<std::size_t ...sequence> constexpr RectangularMatrix<cols, rows, T> flippedRowsInternal(Corrade::Containers::Implementation::Sequence<sequence...>) const {
return {_data[sequence].flipped()...};
}
template<std::size_t ...sequence> constexpr Vector<DiagonalSize, T> diagonalInternal(Implementation::Sequence<sequence...>) const;
template<std::size_t ...sequence> constexpr Vector<DiagonalSize, T> diagonalInternal(Corrade::Containers::Implementation::Sequence<sequence...>) const;
Vector<rows, T> _data[cols];
};
@ -713,15 +713,15 @@ extern template MAGNUM_EXPORT Corrade::Utility::Debug& operator<<(Corrade::Utili
#endif
namespace Implementation {
template<std::size_t rows, std::size_t i, class T, std::size_t ...sequence> constexpr Vector<rows, T> diagonalMatrixColumn2(Implementation::Sequence<sequence...>, const T& number) {
template<std::size_t rows, std::size_t i, class T, std::size_t ...sequence> constexpr Vector<rows, T> diagonalMatrixColumn2(Corrade::Containers::Implementation::Sequence<sequence...>, const T& number) {
return {(sequence == i ? number : T(0))...};
}
template<std::size_t rows, std::size_t i, class T> constexpr Vector<rows, T> diagonalMatrixColumn(const T& number) {
return diagonalMatrixColumn2<rows, i, T>(typename Implementation::GenerateSequence<rows>::Type(), number);
return diagonalMatrixColumn2<rows, i, T>(typename Corrade::Containers::Implementation::GenerateSequence<rows>::Type{}, number);
}
}
template<std::size_t cols, std::size_t rows, class T> template<std::size_t ...sequence> constexpr RectangularMatrix<cols, rows, T>::RectangularMatrix(Implementation::Sequence<sequence...>, const Vector<DiagonalSize, T>& diagonal): _data{Implementation::diagonalMatrixColumn<rows, sequence>(sequence < DiagonalSize ? diagonal[sequence] : T{})...} {}
template<std::size_t cols, std::size_t rows, class T> template<std::size_t ...sequence> constexpr RectangularMatrix<cols, rows, T>::RectangularMatrix(Corrade::Containers::Implementation::Sequence<sequence...>, const Vector<DiagonalSize, T>& diagonal): _data{Implementation::diagonalMatrixColumn<rows, sequence>(sequence < DiagonalSize ? diagonal[sequence] : T{})...} {}
template<std::size_t cols, std::size_t rows, class T> inline Vector<cols, T> RectangularMatrix<cols, rows, T>::row(std::size_t row) const {
Vector<cols, T> out;
@ -776,7 +776,7 @@ template<std::size_t cols, std::size_t rows, class T> inline RectangularMatrix<r
}
#ifndef DOXYGEN_GENERATING_OUTPUT
template<std::size_t cols, std::size_t rows, class T> template<std::size_t ...sequence> constexpr auto RectangularMatrix<cols, rows, T>::diagonalInternal(Implementation::Sequence<sequence...>) const -> Vector<DiagonalSize, T> {
template<std::size_t cols, std::size_t rows, class T> template<std::size_t ...sequence> constexpr auto RectangularMatrix<cols, rows, T>::diagonalInternal(Corrade::Containers::Implementation::Sequence<sequence...>) const -> Vector<DiagonalSize, T> {
return {_data[sequence][sequence]...};
}
#endif

4
src/Magnum/Math/Swizzle.h

@ -90,7 +90,7 @@ namespace Implementation {
template<std::size_t size> struct ScatterComponent<size, 'b', 2>: ScatterComponentOr<size, 2> {};
template<std::size_t size> struct ScatterComponent<size, 'a', 3>: ScatterComponentOr<size, 3> {};
template<class T, char component, std::size_t ...sequence> constexpr T scatterComponentOr(const T& vector, const typename T::Type& value, Sequence<sequence...>) {
template<class T, char component, std::size_t ...sequence> constexpr T scatterComponentOr(const T& vector, const typename T::Type& value, Corrade::Containers::Implementation::Sequence<sequence...>) {
return {ScatterComponent<T::Size, component, sequence>::value(vector, value)...};
}
template<class T, std::size_t valueSize> constexpr T scatterRecursive(const T& vector, const Vector<valueSize, typename T::Type>&, std::size_t) {
@ -98,7 +98,7 @@ namespace Implementation {
}
template<class T, std::size_t valueSize, char component, char ...next> constexpr T scatterRecursive(const T& vector, const Vector<valueSize, typename T::Type>& values, std::size_t valueIndex) {
return scatterRecursive<T, valueSize, next...>(
scatterComponentOr<T, component>(vector, values._data[valueIndex], typename GenerateSequence<T::Size>::Type{}),
scatterComponentOr<T, component>(vector, values._data[valueIndex], typename Corrade::Containers::Implementation::GenerateSequence<T::Size>::Type{}),
values, valueIndex + 1);
}
}

16
src/Magnum/Math/Vector.h

@ -177,7 +177,7 @@ template<std::size_t size, class T> class Vector {
* @see @ref Vector4::pad(const Vector<otherSize, T>&, T, T)
*/
template<std::size_t otherSize> constexpr static Vector<size, T> pad(const Vector<otherSize, T>& a, T value = T()) {
return padInternal<otherSize>(typename Implementation::GenerateSequence<size>::Type(), a, value);
return padInternal<otherSize>(typename Corrade::Containers::Implementation::GenerateSequence<size>::Type{}, a, value);
}
/**
@ -210,7 +210,7 @@ template<std::size_t size, class T> class Vector {
#ifdef DOXYGEN_GENERATING_OUTPUT
constexpr explicit Vector(T value) noexcept;
#else
template<class U, class V = typename std::enable_if<std::is_same<T, U>::value && size != 1, T>::type> constexpr explicit Vector(U value) noexcept: Vector(typename Implementation::GenerateSequence<size>::Type(), value) {}
template<class U, class V = typename std::enable_if<std::is_same<T, U>::value && size != 1, T>::type> constexpr explicit Vector(U value) noexcept: Vector(typename Corrade::Containers::Implementation::GenerateSequence<size>::Type{}, value) {}
#endif
/**
@ -221,7 +221,7 @@ template<std::size_t size, class T> class Vector {
*
* @snippet MagnumMath.cpp Vector-conversion
*/
template<class U> constexpr explicit Vector(const Vector<size, U>& other) noexcept: Vector(typename Implementation::GenerateSequence<size>::Type(), other) {}
template<class U> constexpr explicit Vector(const Vector<size, U>& other) noexcept: Vector(typename Corrade::Containers::Implementation::GenerateSequence<size>::Type{}, other) {}
/** @brief Construct a vector from external representation */
template<class U, class V = decltype(Implementation::VectorConverter<size, T, U>::from(std::declval<U>()))> constexpr explicit Vector(const U& other) noexcept: Vector(Implementation::VectorConverter<size, T, U>::from(other)) {}
@ -623,7 +623,7 @@ template<std::size_t size, class T> class Vector {
* @ref RectangularMatrix::flippedRows()
*/
constexpr Vector<size, T> flipped() const {
return flippedInternal(typename Implementation::GenerateSequence<size>::Type{});
return flippedInternal(typename Corrade::Containers::Implementation::GenerateSequence<size>::Type{});
}
/**
@ -692,16 +692,16 @@ template<std::size_t size, class T> class Vector {
template<std::size_t size_, class U> friend U dot(const Vector<size_, U>&, const Vector<size_, U>&);
/* Implementation for Vector<size, T>::Vector(const Vector<size, U>&) */
template<class U, std::size_t ...sequence> constexpr explicit Vector(Implementation::Sequence<sequence...>, const Vector<size, U>& vector) noexcept: _data{T(vector._data[sequence])...} {}
template<class U, std::size_t ...sequence> constexpr explicit Vector(Corrade::Containers::Implementation::Sequence<sequence...>, const Vector<size, U>& vector) noexcept: _data{T(vector._data[sequence])...} {}
/* Implementation for Vector<size, T>::Vector(U) */
template<std::size_t ...sequence> constexpr explicit Vector(Implementation::Sequence<sequence...>, T value) noexcept: _data{Implementation::repeat(value, sequence)...} {}
template<std::size_t ...sequence> constexpr explicit Vector(Corrade::Containers::Implementation::Sequence<sequence...>, T value) noexcept: _data{Implementation::repeat(value, sequence)...} {}
template<std::size_t otherSize, std::size_t ...sequence> constexpr static Vector<size, T> padInternal(Implementation::Sequence<sequence...>, const Vector<otherSize, T>& a, T value) {
template<std::size_t otherSize, std::size_t ...sequence> constexpr static Vector<size, T> padInternal(Corrade::Containers::Implementation::Sequence<sequence...>, const Vector<otherSize, T>& a, T value) {
return {sequence < otherSize ? a[sequence] : value...};
}
template<std::size_t ...sequence> constexpr Vector<size, T> flippedInternal(Implementation::Sequence<sequence...>) const {
template<std::size_t ...sequence> constexpr Vector<size, T> flippedInternal(Corrade::Containers::Implementation::Sequence<sequence...>) const {
return {_data[size - 1 - sequence]...};
}
};

8
src/Magnum/Trade/MaterialData.h

@ -1266,8 +1266,8 @@ class MAGNUM_TRADE_EXPORT MaterialAttributeData {
right after the null-terminated string) makes them accessible in O(1)
as well. */
struct StringData {
template<std::size_t ...sequence> constexpr explicit StringData(MaterialAttributeType type, Containers::StringView name, Containers::StringView value, Math::Implementation::Sequence<sequence...>): type{type}, nameValue{(sequence < name.size() ? name[sequence] : (sequence - (Implementation::MaterialAttributeDataSize - value.size() - 3) < value.size() ? value[sequence - (Implementation::MaterialAttributeDataSize - value.size() - 3)] : '\0'))...}, size{UnsignedByte(value.size())} {}
constexpr explicit StringData(MaterialAttributeType type, Containers::StringView name, Containers::StringView value): StringData{type, name, value, typename Math::Implementation::GenerateSequence<Implementation::MaterialAttributeDataSize - 2>::Type{}} {}
template<std::size_t ...sequence> constexpr explicit StringData(MaterialAttributeType type, Containers::StringView name, Containers::StringView value, Containers::Implementation::Sequence<sequence...>): type{type}, nameValue{(sequence < name.size() ? name[sequence] : (sequence - (Implementation::MaterialAttributeDataSize - value.size() - 3) < value.size() ? value[sequence - (Implementation::MaterialAttributeDataSize - value.size() - 3)] : '\0'))...}, size{UnsignedByte(value.size())} {}
constexpr explicit StringData(MaterialAttributeType type, Containers::StringView name, Containers::StringView value): StringData{type, name, value, typename Containers::Implementation::GenerateSequence<Implementation::MaterialAttributeDataSize - 2>::Type{}} {}
MaterialAttributeType type;
char nameValue[Implementation::MaterialAttributeDataSize - 2];
@ -1309,8 +1309,8 @@ class MAGNUM_TRADE_EXPORT MaterialAttributeData {
Math::RectangularMatrix<rows, cols, Float> b;
};
template<class T> struct Data {
template<class U, std::size_t ...sequence> constexpr explicit Data(MaterialAttributeType type, Containers::StringView name, const U& value, Math::Implementation::Sequence<sequence...>): type{type}, name{(sequence < name.size() ? name[sequence] : '\0')...}, value{value} {}
template<class U> constexpr explicit Data(MaterialAttributeType type, Containers::StringView name, const U& value): Data{type, name, value, typename Math::Implementation::GenerateSequence<63 - sizeof(T)>::Type{}} {}
template<class U, std::size_t ...sequence> constexpr explicit Data(MaterialAttributeType type, Containers::StringView name, const U& value, Containers::Implementation::Sequence<sequence...>): type{type}, name{(sequence < name.size() ? name[sequence] : '\0')...}, value{value} {}
template<class U> constexpr explicit Data(MaterialAttributeType type, Containers::StringView name, const U& value): Data{type, name, value, typename Containers::Implementation::GenerateSequence<63 - sizeof(T)>::Type{}} {}
MaterialAttributeType type;
char name[Implementation::MaterialAttributeDataSize - sizeof(MaterialAttributeType) - sizeof(T)];

Loading…
Cancel
Save