From d1dcc4d8cdc36520dcc6cda4ad02eca8607f7b79 Mon Sep 17 00:00:00 2001 From: Mikhail Svetkin Date: Tue, 29 May 2018 14:13:59 +0200 Subject: [PATCH] corelib/tools: add qMakeArray() API This function can be used to create std::array without the need to explicitly provide the size of array. It also has a specialization that allow to generate sorted array at compile time. Sorted array can be beneficial for example in binary search. Change-Id: Ifc7e06e451812fce2ab94293959db5e9cc038793 Reviewed-by: Gatis Paeglis --- src/corelib/tools/qmakearray_p.h | 179 ++++++++++++++++++ src/corelib/tools/tools.pri | 1 + .../corelib/tools/qmakearray/qmakearray.pro | 4 + .../tools/qmakearray/tst_qmakearray.cpp | 103 ++++++++++ tests/auto/corelib/tools/tools.pro | 1 + 5 files changed, 288 insertions(+) create mode 100644 src/corelib/tools/qmakearray_p.h create mode 100644 tests/auto/corelib/tools/qmakearray/qmakearray.pro create mode 100644 tests/auto/corelib/tools/qmakearray/tst_qmakearray.cpp diff --git a/src/corelib/tools/qmakearray_p.h b/src/corelib/tools/qmakearray_p.h new file mode 100644 index 00000000000..ae4d7f07c66 --- /dev/null +++ b/src/corelib/tools/qmakearray_p.h @@ -0,0 +1,179 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMAKEARRAY_P_H +#define QMAKEARRAY_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "QtCore/qglobal.h" + +#include +#include +#include + +QT_BEGIN_NAMESPACE + +namespace QtPrivate { +template +constexpr T&& Forward(typename std::remove_reference::type& t) noexcept +{ + return static_cast(t); +} + +template +constexpr T&& Forward(typename std::remove_reference::type&& t) noexcept +{ + static_assert(!std::is_lvalue_reference::value, + "template argument substituting T is an lvalue reference type"); + return static_cast(t); +} + +template +struct ArrayTypeHelper +{ + using type = ManualType; +}; + +template +struct ArrayTypeHelper : std::common_type { }; + +template +using ArrayType = std::array::type, + sizeof...(Types)>; + +template +struct QuickSortData { }; + +template