Просмотр исходного кода

math: fix C++ compliance issues with default vector constructors.

legacy
Sam Hocevar 5 лет назад
Родитель
Сommit
95c1e9db82
2 измененных файлов: 30 добавлений и 29 удалений
  1. +9
    -7
      src/lol/math/transform.h
  2. +21
    -22
      src/lol/math/vector.h

+ 9
- 7
src/lol/math/transform.h Просмотреть файл

@@ -17,6 +17,8 @@
// ---------------------------------------------------
//

#include <lol/math/vector.h>

#include <ostream>

namespace lol
@@ -34,7 +36,8 @@ struct LOL_ATTR_NODISCARD cmplx_t : public linear_ops::base<T>
typedef T element;
typedef cmplx_t<T> type;

inline constexpr cmplx_t() {}
inline constexpr cmplx_t() = default;
inline constexpr cmplx_t(cmplx_t<T> const &) = default;
inline constexpr cmplx_t(T X) : x(X), y(T(0)) {}
inline constexpr cmplx_t(T X, T Y) : x(X), y(Y) {}

@@ -82,9 +85,8 @@ struct LOL_ATTR_NODISCARD quat_t : public linear_ops::base<T>
typedef quat_t<T> type;

/* Default constructor and copy constructor */
inline constexpr quat_t() : w(), x(), y(), z() {}
inline constexpr quat_t(quat_t<T> const &q)
: w(q.w), x(q.x), y(q.y), z(q.z) {}
inline constexpr quat_t() = default;
inline constexpr quat_t(quat_t<T> const &) = default;

/* Explicit constructor for type conversion */
template<typename U>
@@ -257,9 +259,9 @@ template<typename T>
struct LOL_ATTR_NODISCARD sqt_t
{
/* Default constructor and copy constructor */
inline constexpr sqt_t() : s(), q(), t() {}
inline constexpr sqt_t(sqt_t<T> const &other)
: q(other.q), t(other.t), s(other.s) {}
inline constexpr sqt_t() = default;
inline constexpr sqt_t(sqt_t<T> const &) = default;
inline constexpr sqt_t<T>& operator =(const sqt_t<T>&) = default;

/* Explicit constructor for type conversion */
template<typename U>


+ 21
- 22
src/lol/math/vector.h Просмотреть файл

@@ -93,6 +93,25 @@ struct LOL_ATTR_NODISCARD vec_t
}
};

/*
* Helper macros for vector type member functions
*/

#define LOL_COMMON_MEMBER_OPS(first) \
inline T& operator[](size_t n) { return (&this->first)[n]; } \
inline T const& operator[](size_t n) const { return (&this->first)[n]; } \
\
/* An explicit assignment operator is now mandatory */ \
inline type & operator =(type const &that) \
{ \
for (int i = 0; i < type::count; ++i) \
(*this)[i] = that[i]; \
return *this; \
} \
\
void printf() const; \
std::string tostring() const;

/* The generic “vec_t” type, which is a fixed-size vector with no
* swizzling. There's an override for N=2, N=3, N=4 that has swizzling. */
template<typename T, int N>
@@ -113,6 +132,8 @@ struct LOL_ATTR_NODISCARD vec_t<T, N, FULL_SWIZZLE>
}
inline ~vec_t() {}

LOL_COMMON_MEMBER_OPS(m_data[0])

/* Explicit constructor that takes exactly N arguments thanks to SFINAE. */
template<typename... ARGS>
#if LOL_FEATURE_CXX11_SFINAE_FOR_CTORS
@@ -164,9 +185,6 @@ struct LOL_ATTR_NODISCARD vec_t<T, N, FULL_SWIZZLE>
m_data[i] = T(0);
}

inline T& operator[](size_t n) { return m_data[n]; }
inline T const& operator[](size_t n) const { return m_data[n]; }

static const vec_t<T,N> zero;

private:
@@ -185,25 +203,6 @@ private:
T m_data[count];
};

/*
* Helper macros for vector type member functions
*/

#define LOL_COMMON_MEMBER_OPS(first) \
inline T& operator[](size_t n) { return (&this->first)[n]; } \
inline T const& operator[](size_t n) const { return (&this->first)[n]; } \
\
/* Visual Studio insists on having an assignment operator. */ \
inline type & operator =(type const &that) \
{ \
for (int i = 0; i < type::count; ++i) \
(*this)[i] = that[i]; \
return *this; \
} \
\
void printf() const; \
std::string tostring() const;

/*
* 2-element vectors
*/


Загрузка…
Отмена
Сохранить