summaryrefslogtreecommitdiffstats
path: root/src/gui/math3d
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-03-15 09:54:29 +0100
committerMarc Mutz <marc.mutz@qt.io>2023-03-16 06:21:42 +0100
commit9e18e5c869dbef1f0d9a79e899538ab680e14772 (patch)
treeeb717cfcb6f87e7fd1b89adaf5c1ed83bfebc51a /src/gui/math3d
parent49e5f2190830e27e25b57fd12d8c3b99a5c82a23 (diff)
Modernize Tuple Protocol implementations
The existing get<I>() implementations are very cleverâ„¢, if I, as their inventor in at least the Qt ecosystem, may say so myself. E.g. the () around the return value are absolutely required, to ensure we return by reference, not by value, through decltype(auto). C++23 gives us forward_like, which doesn't require the parentheses, because it always returns a reference. Also replace decay_t with C++20's remove_cvref_t, the latter being more efficient (performs less work). Change-Id: Ic9ed0c25e6d6bfbd77d7c85858a8d97fe58be615 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/gui/math3d')
-rw-r--r--src/gui/math3d/qvectornd.h15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/gui/math3d/qvectornd.h b/src/gui/math3d/qvectornd.h
index 0f3ce758a8..639b8f0e5a 100644
--- a/src/gui/math3d/qvectornd.h
+++ b/src/gui/math3d/qvectornd.h
@@ -10,6 +10,9 @@
#include <QtCore/qrect.h>
#include <QtCore/qmath.h>
+#include <QtCore/q20type_traits.h>
+#include <QtCore/q23utility.h>
+
QT_BEGIN_NAMESPACE
class QVector2D;
@@ -145,10 +148,10 @@ private:
template <std::size_t I,
typename V,
std::enable_if_t<(I < 2), bool> = true,
- std::enable_if_t<std::is_same_v<std::decay_t<V>, QVector2D>, bool> = true>
+ std::enable_if_t<std::is_same_v<q20::remove_cvref_t<V>, QVector2D>, bool> = true>
friend constexpr decltype(auto) get(V &&vec) noexcept
{
- return (std::forward<V>(vec).v[I]);
+ return q23::forward_like<V>(vec.v[I]);
}
};
@@ -304,10 +307,10 @@ private:
template <std::size_t I,
typename V,
std::enable_if_t<(I < 3), bool> = true,
- std::enable_if_t<std::is_same_v<std::decay_t<V>, QVector3D>, bool> = true>
+ std::enable_if_t<std::is_same_v<q20::remove_cvref_t<V>, QVector3D>, bool> = true>
friend constexpr decltype(auto) get(V &&vec) noexcept
{
- return (std::forward<V>(vec).v[I]);
+ return q23::forward_like<V>(vec.v[I]);
}
};
@@ -456,10 +459,10 @@ private:
template <std::size_t I,
typename V,
std::enable_if_t<(I < 4), bool> = true,
- std::enable_if_t<std::is_same_v<std::decay_t<V>, QVector4D>, bool> = true>
+ std::enable_if_t<std::is_same_v<q20::remove_cvref_t<V>, QVector4D>, bool> = true>
friend constexpr decltype(auto) get(V &&vec) noexcept
{
- return (std::forward<V>(vec).v[I]);
+ return q23::forward_like<V>(vec.v[I]);
}
};