diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-03-19 17:57:05 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2020-11-20 16:01:14 +0200 |
commit | fb6b7869e8bdda94f7e791db7f281f3bb6e0e004 (patch) | |
tree | cbc3b1bcbd3fab1057fa0b0fc01c25811e7adfa2 /src | |
parent | 7d5ba1c17ecbb620731ff7322fd278c3ce496dad (diff) |
QPoint(F): add support for structured binding
QPoint(F) are "naturally" destructurable in their x/y
counterparts (hello Mac/Carbon users, we don't live in 1999
any more, it's x and then y, and not vice versa...).
[ChangeLog][QtCore][QPoint] QPoint is usable in a structured
binding.
[ChangeLog][QtCore][QPointF] QPointF is usable in a structured
binding.
Change-Id: I8718a4e80be4ce03f37f012034f1fba009304b32
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qpoint.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/corelib/tools/qpoint.h b/src/corelib/tools/qpoint.h index d69e793d3a..f2acb9f3ad 100644 --- a/src/corelib/tools/qpoint.h +++ b/src/corelib/tools/qpoint.h @@ -115,6 +115,18 @@ private: friend class QTransform; int xp; int yp; + + template <std::size_t I, + typename P, + std::enable_if_t<(I < 2), bool> = true, + std::enable_if_t<std::is_same_v<std::decay_t<P>, QPoint>, bool> = true> + friend constexpr decltype(auto) get(P &&p) noexcept + { + if constexpr (I == 0) + return (std::forward<P>(p).xp); + else if constexpr (I == 1) + return (std::forward<P>(p).yp); + } }; Q_DECLARE_TYPEINFO(QPoint, Q_MOVABLE_TYPE); @@ -297,6 +309,18 @@ private: qreal xp; qreal yp; + + template <std::size_t I, + typename P, + std::enable_if_t<(I < 2), bool> = true, + std::enable_if_t<std::is_same_v<std::decay_t<P>, QPointF>, bool> = true> + friend constexpr decltype(auto) get(P &&p) noexcept + { + if constexpr (I == 0) + return (std::forward<P>(p).xp); + else if constexpr (I == 1) + return (std::forward<P>(p).yp); + } }; Q_DECLARE_TYPEINFO(QPointF, Q_MOVABLE_TYPE); @@ -398,4 +422,24 @@ Q_CORE_EXPORT QDebug operator<<(QDebug d, const QPointF &p); QT_END_NAMESPACE +/***************************************************************************** + QPoint/QPointF tuple protocol + *****************************************************************************/ + +namespace std { + template <> + class tuple_size<QT_PREPEND_NAMESPACE(QPoint)> : public integral_constant<size_t, 2> {}; + template <> + class tuple_element<0, QT_PREPEND_NAMESPACE(QPoint)> { public: using type = int; }; + template <> + class tuple_element<1, QT_PREPEND_NAMESPACE(QPoint)> { public: using type = int; }; + + template <> + class tuple_size<QT_PREPEND_NAMESPACE(QPointF)> : public integral_constant<size_t, 2> {}; + template <> + class tuple_element<0, QT_PREPEND_NAMESPACE(QPointF)> { public: using type = QT_PREPEND_NAMESPACE(qreal); }; + template <> + class tuple_element<1, QT_PREPEND_NAMESPACE(QPointF)> { public: using type = QT_PREPEND_NAMESPACE(qreal); }; +} + #endif // QPOINT_H |