Rename QtPrivate::is_[un]signed to QtPrivate::Is[Un]signedEnum

Any other use than for enums should use std::is_[un]signed. Make this
explicit by renaming the type traits.

Change-Id: I494158563c95c710e710d0d337f4e547006df171
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Kai Koehne 2016-08-08 09:41:57 +02:00
parent 5c3b16706f
commit 615270a300
3 changed files with 26 additions and 25 deletions

View File

@ -103,7 +103,7 @@ public:
typedef int Int; typedef int Int;
#else #else
typedef typename std::conditional< typedef typename std::conditional<
QtPrivate::is_unsigned<Enum>::value, QtPrivate::QIsUnsignedEnum<Enum>::value,
unsigned int, unsigned int,
signed int signed int
>::type Int; >::type Int;

View File

@ -47,7 +47,8 @@ QT_BEGIN_NAMESPACE
namespace QtPrivate { namespace QtPrivate {
// //
// define custom is_signed, is_unsigned that also works with enum's // Define QIsUnsignedEnum, QIsSignedEnum -
// std::is_signed, std::is_unsigned does not work for enum's
// //
// a metafunction to invert an integral_constant: // a metafunction to invert an integral_constant:
@ -57,37 +58,37 @@ struct not_
// Checks whether a type is unsigned (T must be convertible to unsigned int): // Checks whether a type is unsigned (T must be convertible to unsigned int):
template <typename T> template <typename T>
struct is_unsigned struct QIsUnsignedEnum
: std::integral_constant<bool, (T(0) < T(-1))> {}; : std::integral_constant<bool, (T(0) < T(-1))> {};
// Checks whether a type is signed (T must be convertible to int): // Checks whether a type is signed (T must be convertible to int):
template <typename T> template <typename T>
struct is_signed struct QIsSignedEnum
: not_< is_unsigned<T> > {}; : not_< QIsUnsignedEnum<T> > {};
Q_STATIC_ASSERT(( is_unsigned<quint8>::value)); Q_STATIC_ASSERT(( QIsUnsignedEnum<quint8>::value));
Q_STATIC_ASSERT((!is_unsigned<qint8>::value)); Q_STATIC_ASSERT((!QIsUnsignedEnum<qint8>::value));
Q_STATIC_ASSERT((!is_signed<quint8>::value)); Q_STATIC_ASSERT((!QIsSignedEnum<quint8>::value));
Q_STATIC_ASSERT(( is_signed<qint8>::value)); Q_STATIC_ASSERT(( QIsSignedEnum<qint8>::value));
Q_STATIC_ASSERT(( is_unsigned<quint16>::value)); Q_STATIC_ASSERT(( QIsUnsignedEnum<quint16>::value));
Q_STATIC_ASSERT((!is_unsigned<qint16>::value)); Q_STATIC_ASSERT((!QIsUnsignedEnum<qint16>::value));
Q_STATIC_ASSERT((!is_signed<quint16>::value)); Q_STATIC_ASSERT((!QIsSignedEnum<quint16>::value));
Q_STATIC_ASSERT(( is_signed<qint16>::value)); Q_STATIC_ASSERT(( QIsSignedEnum<qint16>::value));
Q_STATIC_ASSERT(( is_unsigned<quint32>::value)); Q_STATIC_ASSERT(( QIsUnsignedEnum<quint32>::value));
Q_STATIC_ASSERT((!is_unsigned<qint32>::value)); Q_STATIC_ASSERT((!QIsUnsignedEnum<qint32>::value));
Q_STATIC_ASSERT((!is_signed<quint32>::value)); Q_STATIC_ASSERT((!QIsSignedEnum<quint32>::value));
Q_STATIC_ASSERT(( is_signed<qint32>::value)); Q_STATIC_ASSERT(( QIsSignedEnum<qint32>::value));
Q_STATIC_ASSERT(( is_unsigned<quint64>::value)); Q_STATIC_ASSERT(( QIsUnsignedEnum<quint64>::value));
Q_STATIC_ASSERT((!is_unsigned<qint64>::value)); Q_STATIC_ASSERT((!QIsUnsignedEnum<qint64>::value));
Q_STATIC_ASSERT((!is_signed<quint64>::value)); Q_STATIC_ASSERT((!QIsSignedEnum<quint64>::value));
Q_STATIC_ASSERT(( is_signed<qint64>::value)); Q_STATIC_ASSERT(( QIsSignedEnum<qint64>::value));
} // namespace QtPrivate } // namespace QtPrivate

View File

@ -134,11 +134,11 @@ void tst_QFlags::signedness()
// underlying type is implementation-defined, we need to allow for // underlying type is implementation-defined, we need to allow for
// a different signedness, so we only check that the relative // a different signedness, so we only check that the relative
// signedness of the types matches: // signedness of the types matches:
Q_STATIC_ASSERT((QtPrivate::is_unsigned<Qt::MouseButton>::value == Q_STATIC_ASSERT((QtPrivate::QIsUnsignedEnum<Qt::MouseButton>::value ==
QtPrivate::is_unsigned<Qt::MouseButtons::Int>::value)); QtPrivate::QIsUnsignedEnum<Qt::MouseButtons::Int>::value));
Q_STATIC_ASSERT((QtPrivate::is_signed<Qt::AlignmentFlag>::value == Q_STATIC_ASSERT((QtPrivate::QIsSignedEnum<Qt::AlignmentFlag>::value ==
QtPrivate::is_signed<Qt::Alignment::Int>::value)); QtPrivate::QIsSignedEnum<Qt::Alignment::Int>::value));
} }
#if defined(Q_COMPILER_CLASS_ENUM) #if defined(Q_COMPILER_CLASS_ENUM)