mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
refs #628 Provide more of the API of our std::integer_sequence substitute.
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef BLACKMISC_INDEX_SEQUENCE_H
|
||||
#define BLACKMISC_INDEX_SEQUENCE_H
|
||||
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <cstddef>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Private
|
||||
{
|
||||
|
||||
// Inhibit doxygen warnings about missing documentation
|
||||
//! \cond PRIVATE
|
||||
|
||||
// Our own implementation of std::index_sequence (because not implemented by GCC 4.9)
|
||||
template <size_t... Is>
|
||||
struct index_sequence
|
||||
{
|
||||
static const size_t size = sizeof...(Is);
|
||||
using tuple_type = std::tuple<std::integral_constant<size_t, Is>...>;
|
||||
};
|
||||
template <size_t I, size_t C, size_t... Is>
|
||||
struct GenSequence
|
||||
{
|
||||
using type = typename GenSequence<I + 1, C, Is..., I>::type;
|
||||
};
|
||||
template <size_t C, size_t... Is>
|
||||
struct GenSequence<C, C, Is...>
|
||||
{
|
||||
using type = index_sequence<Is...>;
|
||||
};
|
||||
template <size_t C>
|
||||
using make_index_sequence = typename GenSequence<0, C>::type;
|
||||
|
||||
//! \endcond
|
||||
|
||||
} // namespace Private
|
||||
|
||||
} // namespace BlackMisc
|
||||
|
||||
#endif // guard
|
||||
88
src/blackmisc/integersequence.h
Normal file
88
src/blackmisc/integersequence.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_INTEGERSEQUENCE_H
|
||||
#define BLACKMISC_INTEGERSEQUENCE_H
|
||||
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <cstddef>
|
||||
|
||||
#if ! (defined(Q_CC_GNU) && __GNUC__ <= 4)
|
||||
//! \private
|
||||
#define BLACK_HAS_INTEGER_SEQUENCE
|
||||
#endif
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
//! \cond PRIVATE
|
||||
namespace Private
|
||||
{
|
||||
|
||||
#ifdef BLACK_HAS_INTEGER_SEQUENCE
|
||||
template <typename T, T... Is>
|
||||
using integer_sequence = std::integer_sequence<T, Is...>;
|
||||
template <typename T, T C>
|
||||
using make_integer_sequence = std::make_integer_sequence<T, C>;
|
||||
#else // Our own implementation of std::integer_sequence (because not implemented by GCC 4.9)
|
||||
template <typename T, T... Is>
|
||||
struct integer_sequence
|
||||
{
|
||||
static const size_t size = sizeof...(Is);
|
||||
typedef std::tuple<std::integral_constant<T, Is>...> tuple_type;
|
||||
};
|
||||
template <typename T, T I, T C, T... Is>
|
||||
struct GenSequence
|
||||
{
|
||||
typedef typename GenSequence<T, I + 1, C, Is..., I>::type type;
|
||||
};
|
||||
template <typename T, T C, T... Is>
|
||||
struct GenSequence<T, C, C, Is...>
|
||||
{
|
||||
typedef integer_sequence<T, Is...> type;
|
||||
};
|
||||
template <typename T, T C>
|
||||
using make_integer_sequence = typename GenSequence<T, 0, C>::type;
|
||||
#endif // ! BLACK_HAS_INTEGER_SEQUENCE
|
||||
template <size_t... Is>
|
||||
using index_sequence = integer_sequence<size_t, Is...>;
|
||||
template <size_t C>
|
||||
using make_index_sequence = make_integer_sequence<size_t, C>;
|
||||
|
||||
// Remove elements from an index_sequence for which a pack parameter fails to satisfy a given predicate.
|
||||
template <typename, typename T, bool...>
|
||||
struct MaskSequenceImpl
|
||||
{
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template <size_t I, size_t... Is, bool... Mask, size_t... Js>
|
||||
struct MaskSequenceImpl<index_sequence<I, Is...>, index_sequence<Js...>, true, Mask...>
|
||||
{
|
||||
using type = typename MaskSequenceImpl<index_sequence<Is...>, index_sequence<Js..., I>, Mask...>::type;
|
||||
};
|
||||
|
||||
template <size_t I, size_t... Is, bool... Mask, size_t... Js>
|
||||
struct MaskSequenceImpl<index_sequence<I, Is...>, index_sequence<Js...>, false, Mask...>
|
||||
{
|
||||
using type = typename MaskSequenceImpl<index_sequence<Is...>, index_sequence<Js...>, Mask...>::type;
|
||||
};
|
||||
|
||||
template <typename Seq, bool... Mask>
|
||||
using MaskSequence = typename MaskSequenceImpl<Seq, Private::index_sequence<>, Mask...>::type;
|
||||
|
||||
} // namespace Private
|
||||
//! \endcond
|
||||
|
||||
} // namespace BlackMisc
|
||||
|
||||
#endif // guard
|
||||
@@ -10,7 +10,6 @@
|
||||
//! \cond PRIVATE
|
||||
|
||||
#include "logmessage.h"
|
||||
#include "indexsequence.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include "statusmessagelist.h"
|
||||
#include "statusmessage.h"
|
||||
#include "logcategorylist.h"
|
||||
#include "indexsequence.h"
|
||||
#include "integersequence.h"
|
||||
#include <QDebug>
|
||||
#include <QLoggingCategory>
|
||||
#include <QList>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#ifndef BLACKMISC_PREDICATES_H
|
||||
#define BLACKMISC_PREDICATES_H
|
||||
|
||||
#include "indexsequence.h"
|
||||
#include "integersequence.h"
|
||||
#include <QObject>
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#ifndef BLACKMISC_TUPLE_PRIVATE_H
|
||||
#define BLACKMISC_TUPLE_PRIVATE_H
|
||||
|
||||
#include "indexsequence.h"
|
||||
#include "integersequence.h"
|
||||
#include <QtGlobal>
|
||||
#include <QDBusArgument>
|
||||
#include <QHash>
|
||||
|
||||
Reference in New Issue
Block a user