summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-09-20 15:01:09 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-09-27 02:25:25 +0200
commitd85dd245f9a1a2959af4d2d68a45cf1dca419767 (patch)
treebea032f32be21cfce1759f140cfe99222415249f /src/corelib/global
parenta19fd0f9265bed96197a6823887c6f03fc23112d (diff)
qtypetraits.h: add is_signed/is_unsigned/not_/not_c predicates
is_signed/is_unsigned check whether the type argument is signed or unsigned, resp., and will be used in QFlags to select the correct underlying integer type. not_ is used in the implementation of is_signed not_c is for completeness (version of not_ that takes a bool instead of an integral_constant). Change-Id: I77cc445e8c6cf3181336505c9c13478fba3e7890 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/qtypetraits.h91
1 files changed, 90 insertions, 1 deletions
diff --git a/src/corelib/global/qtypetraits.h b/src/corelib/global/qtypetraits.h
index 92bd949570..0183f33738 100644
--- a/src/corelib/global/qtypetraits.h
+++ b/src/corelib/global/qtypetraits.h
@@ -1,3 +1,46 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// BEGIN Google Code
+
// Copyright (c) 2006, Google Inc.
// All rights reserved.
//
@@ -412,7 +455,53 @@ struct is_convertible
};
#endif
-}
+// END Google Code
+
+// a metafunction to invert an integral_constant:
+template <typename T>
+struct not_
+ : integral_constant<bool, !T::value> {};
+
+// same, with a bool argument:
+template <bool B>
+struct not_c
+ : integral_constant<bool, !B> {};
+
+// Checks whether a type is unsigned (T must be convertible to unsigned int):
+template <typename T>
+struct is_unsigned
+ : integral_constant<bool, (T(0) < T(-1))> {};
+
+// Checks whether a type is signed (T must be convertible to int):
+template <typename T>
+struct is_signed
+ : not_< is_unsigned<T> > {};
+
+Q_STATIC_ASSERT(( is_unsigned<quint8>::value));
+Q_STATIC_ASSERT((!is_unsigned<qint8>::value));
+
+Q_STATIC_ASSERT((!is_signed<quint8>::value));
+Q_STATIC_ASSERT(( is_signed<qint8>::value));
+
+Q_STATIC_ASSERT(( is_unsigned<quint16>::value));
+Q_STATIC_ASSERT((!is_unsigned<qint16>::value));
+
+Q_STATIC_ASSERT((!is_signed<quint16>::value));
+Q_STATIC_ASSERT(( is_signed<qint16>::value));
+
+Q_STATIC_ASSERT(( is_unsigned<quint32>::value));
+Q_STATIC_ASSERT((!is_unsigned<qint32>::value));
+
+Q_STATIC_ASSERT((!is_signed<quint32>::value));
+Q_STATIC_ASSERT(( is_signed<qint32>::value));
+
+Q_STATIC_ASSERT(( is_unsigned<quint64>::value));
+Q_STATIC_ASSERT((!is_unsigned<qint64>::value));
+
+Q_STATIC_ASSERT((!is_signed<quint64>::value));
+Q_STATIC_ASSERT(( is_signed<qint64>::value));
+
+} // namespace QtPrivate
QT_END_NAMESPACE
QT_END_HEADER