From 2ec151886274452fd54024302f5f71760a9665d5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 27 Aug 2018 16:56:57 +0200 Subject: compat/simple-mat: add slice() --- compat/simple-mat.hpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'compat') diff --git a/compat/simple-mat.hpp b/compat/simple-mat.hpp index 2dfdab04..87e1ae83 100644 --- a/compat/simple-mat.hpp +++ b/compat/simple-mat.hpp @@ -64,6 +64,9 @@ class Mat num data[h_][w_]; public: + // 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> constexpr inline operator()(unsigned i) const& { return data[i][0]; } @@ -104,8 +107,18 @@ public: 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 + constexpr Mat slice() const + { + return (const double*)*this; + } + + template std::enable_if_t::value, Mat> + slice() const { return ((double const*)*this) + off; } + + template std::enable_if_t::value && equals::value, + Mat> + slice() const { return ((double const*)*this) + off; } template std::enable_if_t::value, num> @@ -293,7 +306,21 @@ constexpr Mat operator*(const Mat& self, num other) return ret; } +#if 0 +OTR_GENERIC_EXPORT inline void test() +{ + Mat x1 = Mat::eye().slice<1, 1>(); + Mat x2 = Mat().slice<1>(); + Mat x3 = Mat().slice<1>(); + //Mat x4 = Mat().slice<2>(); (void) x4; + + (void) x1; (void) x2; (void) x3; +} +#endif + } // ns simple_mat_detail template using Mat = simple_mat_detail::Mat; + + -- cgit v1.2.3