QPermission: don't hide SFINAE constraints
Like done elsewhere (e.g. in QStringView), formulate the constaint in if_x<T> = true from, and let qdoc see it. Then document the constraint in prose, too. As a drive-by, use C++17 variable templates instead of std::bool_value, and document that data() returns a default-constructed T on failure (which is indistinguishable from a successful call that happens to return a default-constructed T, so we should probably return an optional<T> here, but that's orthogonal to the change at hand). Change-Id: I0584ce3f4febd619d3966afeb6244b11b167cd42 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit 6ac9d46a36f1b6b921efdcb47d7b7241d2396897) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
9d14e35e7b
commit
6b7c5d2daf
@ -229,22 +229,32 @@ Q_LOGGING_CATEGORY(lcPermissions, "qt.permissions", QtWarningMsg);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn template <typename Type> QPermission::QPermission(const Type &type)
|
\fn template <typename T, if_permission<T>> QPermission::QPermission(const T &type)
|
||||||
|
|
||||||
Constructs a permission from the given \l{typed permission} \a type.
|
Constructs a permission from the given \l{typed permission} \a type.
|
||||||
|
|
||||||
You do not need to construct this type explicitly, as the type is automatically
|
You do not need to construct this type explicitly, as the type is automatically
|
||||||
used when checking or requesting permissions.
|
used when checking or requesting permissions.
|
||||||
|
|
||||||
|
This constructor participates in overload resolution only if \c T is one of
|
||||||
|
the \l{typed permission} classes:
|
||||||
|
|
||||||
|
\annotatedlist permissions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn template <typename Type> Type QPermission::data() const
|
\fn template <typename T, if_permission<T>> T QPermission::data() const
|
||||||
|
|
||||||
Returns the \l{typed permission} of type \c Type.
|
Returns the \l{typed permission} of type \c T.
|
||||||
|
|
||||||
The type must match the type that was originally used to request
|
If the type doesn't match the type that was originally used to request the
|
||||||
the permission. Use type() for dynamically choosing which typed
|
permission, returns a default-constructed \c T. Use type() for dynamically
|
||||||
permission to request.
|
choosing which typed permission to request.
|
||||||
|
|
||||||
|
This function participates in overload resolution only if \c T is one of
|
||||||
|
the \l{typed permission} classes:
|
||||||
|
|
||||||
|
\annotatedlist permissions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -34,31 +34,24 @@ class QPermission
|
|||||||
Q_GADGET_EXPORT(Q_CORE_EXPORT)
|
Q_GADGET_EXPORT(Q_CORE_EXPORT)
|
||||||
|
|
||||||
template <typename T, typename Enable = void>
|
template <typename T, typename Enable = void>
|
||||||
struct is_permission : public std::false_type {};
|
static constexpr inline bool is_permission_v = false;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct is_permission<T, typename T::QtPermissionHelper> : public std::true_type {};
|
static constexpr inline bool is_permission_v<T, typename T::QtPermissionHelper> = true;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using if_permission = std::enable_if_t<is_permission_v<T>, bool>;
|
||||||
public:
|
public:
|
||||||
explicit QPermission() = default;
|
explicit QPermission() = default;
|
||||||
|
|
||||||
#ifdef Q_QDOC
|
template <typename T, if_permission<T> = true>
|
||||||
template <typename Type>
|
|
||||||
QPermission(const Type &type);
|
|
||||||
#else
|
|
||||||
template <typename T, std::enable_if_t<is_permission<T>::value, bool> = true>
|
|
||||||
QPermission(const T &t) : m_data(QVariant::fromValue(t)) {}
|
QPermission(const T &t) : m_data(QVariant::fromValue(t)) {}
|
||||||
#endif
|
|
||||||
|
|
||||||
Qt::PermissionStatus status() const { return m_status; }
|
Qt::PermissionStatus status() const { return m_status; }
|
||||||
|
|
||||||
QMetaType type() const { return m_data.metaType(); }
|
QMetaType type() const { return m_data.metaType(); }
|
||||||
|
|
||||||
#ifdef Q_QDOC
|
template <typename T, if_permission<T> = true>
|
||||||
template <typename Type>
|
|
||||||
Type data() const;
|
|
||||||
#else
|
|
||||||
template <typename T, std::enable_if_t<is_permission<T>::value, bool> = true>
|
|
||||||
T data() const
|
T data() const
|
||||||
{
|
{
|
||||||
if (auto p = data(QMetaType::fromType<T>()))
|
if (auto p = data(QMetaType::fromType<T>()))
|
||||||
@ -66,7 +59,6 @@ public:
|
|||||||
else
|
else
|
||||||
return T{};
|
return T{};
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef QT_NO_DEBUG_STREAM
|
#ifndef QT_NO_DEBUG_STREAM
|
||||||
friend Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QPermission &);
|
friend Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QPermission &);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user