From d85dd245f9a1a2959af4d2d68a45cf1dca419767 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 20 Sep 2012 15:01:09 +0200 Subject: [PATCH] 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 --- src/corelib/global/qtypetraits.h | 91 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/src/corelib/global/qtypetraits.h b/src/corelib/global/qtypetraits.h index 92bd949..0183f33 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 +** 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 +struct not_ + : integral_constant {}; + +// same, with a bool argument: +template +struct not_c + : integral_constant {}; + +// Checks whether a type is unsigned (T must be convertible to unsigned int): +template +struct is_unsigned + : integral_constant {}; + +// Checks whether a type is signed (T must be convertible to int): +template +struct is_signed + : not_< is_unsigned > {}; + +Q_STATIC_ASSERT(( is_unsigned::value)); +Q_STATIC_ASSERT((!is_unsigned::value)); + +Q_STATIC_ASSERT((!is_signed::value)); +Q_STATIC_ASSERT(( is_signed::value)); + +Q_STATIC_ASSERT(( is_unsigned::value)); +Q_STATIC_ASSERT((!is_unsigned::value)); + +Q_STATIC_ASSERT((!is_signed::value)); +Q_STATIC_ASSERT(( is_signed::value)); + +Q_STATIC_ASSERT(( is_unsigned::value)); +Q_STATIC_ASSERT((!is_unsigned::value)); + +Q_STATIC_ASSERT((!is_signed::value)); +Q_STATIC_ASSERT(( is_signed::value)); + +Q_STATIC_ASSERT(( is_unsigned::value)); +Q_STATIC_ASSERT((!is_unsigned::value)); + +Q_STATIC_ASSERT((!is_signed::value)); +Q_STATIC_ASSERT(( is_signed::value)); + +} // namespace QtPrivate QT_END_NAMESPACE QT_END_HEADER -- 2.7.4