From 456cc1224d44f5a6cf03b5e7c13c7b85dfab8058 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 17 Oct 2019 13:59:46 +0200 Subject: [PATCH] math: use default constructor for vec_t types. --- src/lol/math/vector.h | 52 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index 05bd4730..54ba3163 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -58,12 +58,6 @@ struct LOL_ATTR_NODISCARD vec_t typedef T element; typedef vec_t type; - /* Disable all default constructors and destructors; this object - * is only intended to exist as part of a union. */ - vec_t() = delete; - vec_t(vec_t const &) = delete; - ~vec_t() = delete; - /* Allow the assignment operator if unrestricted unions are supported. */ inline vec_t& operator =(vec_t that) { @@ -91,6 +85,15 @@ struct LOL_ATTR_NODISCARD vec_t int const i = SWIZZLE / lut[n + 4 - N] % 10; return static_cast(static_cast(this))[i]; } + +private: + // Hide all default constructors and destructors; this object + // is only intended to exist as part of a union. + template friend class vec_t; + + vec_t() = default; + vec_t(vec_t const &) = default; + ~vec_t() = default; }; /* @@ -123,14 +126,10 @@ struct LOL_ATTR_NODISCARD vec_t typedef T element; typedef vec_t type; - /* Default constructor, copy constructor, and destructor */ - inline constexpr vec_t() {} - inline vec_t(vec_t const &v) - { - for (int i = 0; i < N; ++i) - m_data[i] = v[i]; - } - inline ~vec_t() {} + // Default constructor, copy constructor, and destructor + inline constexpr vec_t() = default; + inline constexpr vec_t(type const &v) = default; + inline ~vec_t() = default; LOL_COMMON_MEMBER_OPS(m_data[0]) @@ -216,10 +215,10 @@ struct LOL_ATTR_NODISCARD vec_t typedef T element; typedef vec_t type; - /* Default constructor, copy constructor, and destructor */ - inline constexpr vec_t() : x(), y() {} - inline constexpr vec_t(vec_t const &v) : x(v.x), y(v.y) {} - inline ~vec_t() { x.~T(); y.~T(); } + // Default constructor, copy constructor, and destructor + inline constexpr vec_t() = default; + inline constexpr vec_t(type const &v) = default; + inline ~vec_t() = default; /* Implicit constructor for swizzling */ template @@ -330,10 +329,10 @@ struct LOL_ATTR_NODISCARD vec_t typedef T element; typedef vec_t type; - /* Default constructor, copy constructor, and destructor */ - inline constexpr vec_t() : x(), y(), z() {} - inline constexpr vec_t(vec_t const &v) : x(v.x), y(v.y), z(v.z) {} - inline ~vec_t() { x.~T(); y.~T(); z.~T(); } + // Default constructor, copy constructor, and destructor + inline constexpr vec_t() = default; + inline constexpr vec_t(type const &v) = default; + inline ~vec_t() = default; /* Implicit constructor for swizzling */ template @@ -574,11 +573,10 @@ struct LOL_ATTR_NODISCARD vec_t typedef T element; typedef vec_t type; - /* Default constructor, copy constructor, and destructor */ - inline constexpr vec_t() : x(), y(), z(), w() {} - inline constexpr vec_t(vec_t const &v) - : x(v.x), y(v.y), z(v.z), w(v.w) {} - inline ~vec_t() { x.~T(); y.~T(); z.~T(); w.~T(); } + // Default constructor, copy constructor, and destructor + inline constexpr vec_t() = default; + inline constexpr vec_t(type const &v) = default; + inline ~vec_t() = default; /* Implicit constructor for swizzling */ template