From eeac403cfce10f32da956215b0df4726b82a6f83 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Thu, 24 Mar 2016 22:13:54 +0000 Subject: [PATCH] refs #628 Provide more of the API of our std::integer_sequence substitute. --- src/blackmisc/indexsequence.h | 51 ------------------- src/blackmisc/integersequence.h | 88 +++++++++++++++++++++++++++++++++ src/blackmisc/logmessage.cpp | 1 - src/blackmisc/logmessage.h | 2 +- src/blackmisc/predicates.h | 2 +- src/blackmisc/tupleprivate.h | 2 +- 6 files changed, 91 insertions(+), 55 deletions(-) delete mode 100644 src/blackmisc/indexsequence.h create mode 100644 src/blackmisc/integersequence.h diff --git a/src/blackmisc/indexsequence.h b/src/blackmisc/indexsequence.h deleted file mode 100644 index a75621931..000000000 --- a/src/blackmisc/indexsequence.h +++ /dev/null @@ -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 -#include -#include - -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 - struct index_sequence - { - static const size_t size = sizeof...(Is); - using tuple_type = std::tuple...>; - }; - template - struct GenSequence - { - using type = typename GenSequence::type; - }; - template - struct GenSequence - { - using type = index_sequence; - }; - template - using make_index_sequence = typename GenSequence<0, C>::type; - - //! \endcond - - } // namespace Private - -} // namespace BlackMisc - -#endif // guard diff --git a/src/blackmisc/integersequence.h b/src/blackmisc/integersequence.h new file mode 100644 index 000000000..fc854dfa4 --- /dev/null +++ b/src/blackmisc/integersequence.h @@ -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 +#include +#include + +#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 + using integer_sequence = std::integer_sequence; + template + using make_integer_sequence = std::make_integer_sequence; +#else // Our own implementation of std::integer_sequence (because not implemented by GCC 4.9) + template + struct integer_sequence + { + static const size_t size = sizeof...(Is); + typedef std::tuple...> tuple_type; + }; + template + struct GenSequence + { + typedef typename GenSequence::type type; + }; + template + struct GenSequence + { + typedef integer_sequence type; + }; + template + using make_integer_sequence = typename GenSequence::type; +#endif // ! BLACK_HAS_INTEGER_SEQUENCE + template + using index_sequence = integer_sequence; + template + using make_index_sequence = make_integer_sequence; + + // Remove elements from an index_sequence for which a pack parameter fails to satisfy a given predicate. + template + struct MaskSequenceImpl + { + using type = T; + }; + + template + struct MaskSequenceImpl, index_sequence, true, Mask...> + { + using type = typename MaskSequenceImpl, index_sequence, Mask...>::type; + }; + + template + struct MaskSequenceImpl, index_sequence, false, Mask...> + { + using type = typename MaskSequenceImpl, index_sequence, Mask...>::type; + }; + + template + using MaskSequence = typename MaskSequenceImpl, Mask...>::type; + + } // namespace Private + //! \endcond + +} // namespace BlackMisc + +#endif // guard diff --git a/src/blackmisc/logmessage.cpp b/src/blackmisc/logmessage.cpp index d2ee07186..322b88e5c 100644 --- a/src/blackmisc/logmessage.cpp +++ b/src/blackmisc/logmessage.cpp @@ -10,7 +10,6 @@ //! \cond PRIVATE #include "logmessage.h" -#include "indexsequence.h" namespace BlackMisc { diff --git a/src/blackmisc/logmessage.h b/src/blackmisc/logmessage.h index e775fcec7..595605465 100644 --- a/src/blackmisc/logmessage.h +++ b/src/blackmisc/logmessage.h @@ -16,7 +16,7 @@ #include "statusmessagelist.h" #include "statusmessage.h" #include "logcategorylist.h" -#include "indexsequence.h" +#include "integersequence.h" #include #include #include diff --git a/src/blackmisc/predicates.h b/src/blackmisc/predicates.h index 1924d80cd..1e81b358a 100644 --- a/src/blackmisc/predicates.h +++ b/src/blackmisc/predicates.h @@ -14,7 +14,7 @@ #ifndef BLACKMISC_PREDICATES_H #define BLACKMISC_PREDICATES_H -#include "indexsequence.h" +#include "integersequence.h" #include #include #include diff --git a/src/blackmisc/tupleprivate.h b/src/blackmisc/tupleprivate.h index aa881d3dc..214bea865 100644 --- a/src/blackmisc/tupleprivate.h +++ b/src/blackmisc/tupleprivate.h @@ -10,7 +10,7 @@ #ifndef BLACKMISC_TUPLE_PRIVATE_H #define BLACKMISC_TUPLE_PRIVATE_H -#include "indexsequence.h" +#include "integersequence.h" #include #include #include