From 7d101a1c2827b5e7a373fb0d0a68099fb692e55a Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 9 Jan 2018 17:14:02 +0100 Subject: many: spring cleanup --- compat/macros.hpp | 10 +++++++-- compat/simple-mat.hpp | 57 ++++++++++++++++++++++++--------------------------- 2 files changed, 35 insertions(+), 32 deletions(-) (limited to 'compat') diff --git a/compat/macros.hpp b/compat/macros.hpp index 8f807bf0..ed0bd8da 100644 --- a/compat/macros.hpp +++ b/compat/macros.hpp @@ -45,18 +45,24 @@ #ifdef Q_CREATOR_RUN # define warn_result_unused -#elif defined(_MSC_VER) +#elif defined _MSC_VER # define warn_result_unused _Check_return_ #else # define warn_result_unused __attribute__((warn_unused_result)) #endif -#if defined(__GNUG__) +#if defined __GNUG__ # define unused(t, i) t __attribute__((unused)) i #else # define unused(t, i) t #endif +#if defined _MSC_VER +# define aligned_struct(x) struct __declspec(align(x)) +#else +# define aligned_struct(x) struct __attribute__((__aligned__(x))) +#endif + #if defined __GNUC__ # define likely(x) __builtin_expect(!!(x),1) # define unlikely(x) __builtin_expect(!!(x),0) diff --git a/compat/simple-mat.hpp b/compat/simple-mat.hpp index a806448b..c8c9f48b 100644 --- a/compat/simple-mat.hpp +++ b/compat/simple-mat.hpp @@ -21,11 +21,18 @@ namespace simple_mat_detail { { enum { value = i == j }; }; - template + template struct maybe_add_swizzle { - enum { value = (i == 1 || j == 1) && (i >= min || j >= min) }; + enum { value = (i == 1 || j == 1) && (i >= min || j >= min) && (i <= max || j <= max) }; }; + + template + struct is_vector + { + enum { value = j == 1 || i == 1 }; + }; + template struct is_vector_pair { @@ -57,18 +64,6 @@ class Mat num data[h_][w_]; public: - template std::enable_if_t::value, num> - constexpr inline operator()(int i) const& { return data[i][0]; } - - template std::enable_if_t::value, num> - constexpr inline operator()(int i) const& { return data[0][i]; } - - template std::enable_if_t::value, num&> - constexpr inline operator()(int i) & { return data[i][0]; } - - template std::enable_if_t::value, num&> - constexpr inline operator()(int i) & { return data[0][i]; } - template std::enable_if_t::value, num> constexpr inline operator()(unsigned i) const& { return data[i][0]; } @@ -83,35 +78,37 @@ public: #define OPENTRACK_ASSERT_SWIZZLE static_assert(P == h_ && Q == w_, "") - template std::enable_if_t::value, num> + // const variants + template std::enable_if_t::value, num> constexpr inline x() const& { OPENTRACK_ASSERT_SWIZZLE; return operator()(0); } - template std::enable_if_t::value, num> + template std::enable_if_t::value, num> constexpr inline y() const& { OPENTRACK_ASSERT_SWIZZLE; return operator()(1); } - template std::enable_if_t::value, num> + template std::enable_if_t::value, num> constexpr inline z() const& { OPENTRACK_ASSERT_SWIZZLE; return operator()(2); } - template std::enable_if_t::value, num> + template std::enable_if_t::value, num> constexpr inline w() const& { OPENTRACK_ASSERT_SWIZZLE; return operator()(3); } - template std::enable_if_t::value, num&> + // mutable variants + template std::enable_if_t::value, num&> constexpr inline x() & { OPENTRACK_ASSERT_SWIZZLE; return operator()(0); } - template std::enable_if_t::value, num&> + template std::enable_if_t::value, num&> constexpr inline y() & { OPENTRACK_ASSERT_SWIZZLE; return operator()(1); } - template std::enable_if_t::value, num&> + template std::enable_if_t::value, num&> constexpr inline z() & { OPENTRACK_ASSERT_SWIZZLE; return operator()(2); } - template std::enable_if_t::value, num&> + template std::enable_if_t::value, num&> constexpr inline w() & { OPENTRACK_ASSERT_SWIZZLE; return operator()(3); } // parameters w_ and h_ are rebound so that SFINAE occurs // removing them causes a compile-time error -sh 20150811 - template - std::enable_if_t::value, num> + template + std::enable_if_t::value, num> norm() const { static_assert(P == h_ && Q == w_, ""); @@ -167,7 +164,7 @@ public: return ret; } - constexpr Mat operator+(const num& other) const + constexpr Mat operator+(const num other) const { Mat ret; for (int j = 0; j < h_; j++) @@ -176,7 +173,7 @@ public: return ret; } - constexpr Mat operator-(const num& other) const + constexpr Mat operator-(const num other) const { Mat ret; for (int j = 0; j < h_; j++) @@ -210,11 +207,11 @@ public: return ret; } - constexpr inline num operator()(int j, int i) const& { return data[j][i]; } - constexpr inline num& operator()(int j, int i) & { return data[j][i]; } + template + constexpr inline num operator()(t j, u i) const& { return data[(int) j][(int) i]; } - constexpr inline num operator()(unsigned j, unsigned i) const& { return data[j][i]; } - constexpr inline num& operator()(unsigned j, unsigned i) & { return data[j][i]; } + template + constexpr inline num& operator()(t j, u i) & { return data[(int) j][(int) i]; } #ifdef __GNUG__ # pragma GCC diagnostic push -- cgit v1.2.3