Commit patch for integer sequences. Suggested by Richard, reworked by Howard, and annotated by me
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@185569 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
24ae8f8e5b
commit
42e55e932e
@ -602,7 +602,7 @@ get(pair<_T1, _T2>&& __p) _NOEXCEPT
|
|||||||
#if _LIBCPP_STD_VER > 11
|
#if _LIBCPP_STD_VER > 11
|
||||||
|
|
||||||
template<class _Tp, _Tp... _Ip>
|
template<class _Tp, _Tp... _Ip>
|
||||||
struct integer_sequence
|
struct _LIBCPP_TYPE_VIS integer_sequence
|
||||||
{
|
{
|
||||||
typedef _Tp value_type;
|
typedef _Tp value_type;
|
||||||
static_assert( is_integral<_Tp>::value,
|
static_assert( is_integral<_Tp>::value,
|
||||||
@ -617,26 +617,53 @@ struct integer_sequence
|
|||||||
template<size_t... _Ip>
|
template<size_t... _Ip>
|
||||||
using index_sequence = integer_sequence<size_t, _Ip...>;
|
using index_sequence = integer_sequence<size_t, _Ip...>;
|
||||||
|
|
||||||
template <class _Tp, _Tp _Sp, _Tp _Ep, class _IntSequence>
|
namespace __detail {
|
||||||
struct __make_integer_sequence_unchecked;
|
|
||||||
|
|
||||||
template <class _Tp, _Tp _Sp, _Tp _Ep, _Tp ..._Indices>
|
template<typename _Tp, size_t ..._Extra> struct __repeat;
|
||||||
struct __make_integer_sequence_unchecked<_Tp, _Sp, _Ep,
|
template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<integer_sequence<_Tp, _Np...>, _Extra...> {
|
||||||
integer_sequence<_Tp, _Indices...>>
|
typedef integer_sequence<_Tp,
|
||||||
{
|
_Np...,
|
||||||
typedef typename __make_integer_sequence_unchecked
|
sizeof...(_Np) + _Np...,
|
||||||
<
|
2 * sizeof...(_Np) + _Np...,
|
||||||
_Tp, _Sp+1, _Ep,
|
3 * sizeof...(_Np) + _Np...,
|
||||||
integer_sequence<_Tp, _Indices..., _Sp>
|
4 * sizeof...(_Np) + _Np...,
|
||||||
>::type type;
|
5 * sizeof...(_Np) + _Np...,
|
||||||
|
6 * sizeof...(_Np) + _Np...,
|
||||||
|
7 * sizeof...(_Np) + _Np...,
|
||||||
|
_Extra...> type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class _Tp, _Tp _Ep, _Tp ..._Indices>
|
template<size_t _Np> struct __parity;
|
||||||
struct __make_integer_sequence_unchecked<_Tp, _Ep, _Ep,
|
template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {};
|
||||||
integer_sequence<_Tp, _Indices...>>
|
|
||||||
{
|
template<> struct __make<0> { typedef integer_sequence<size_t> type; };
|
||||||
typedef integer_sequence<_Tp, _Indices...> type;
|
template<> struct __make<1> { typedef integer_sequence<size_t, 0> type; };
|
||||||
|
template<> struct __make<2> { typedef integer_sequence<size_t, 0, 1> type; };
|
||||||
|
template<> struct __make<3> { typedef integer_sequence<size_t, 0, 1, 2> type; };
|
||||||
|
template<> struct __make<4> { typedef integer_sequence<size_t, 0, 1, 2, 3> type; };
|
||||||
|
template<> struct __make<5> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4> type; };
|
||||||
|
template<> struct __make<6> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4, 5> type; };
|
||||||
|
template<> struct __make<7> { typedef integer_sequence<size_t, 0, 1, 2, 3, 4, 5, 6> type; };
|
||||||
|
|
||||||
|
template<> struct __parity<0> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type> {}; };
|
||||||
|
template<> struct __parity<1> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 1> {}; };
|
||||||
|
template<> struct __parity<2> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 2, _Np - 1> {}; };
|
||||||
|
template<> struct __parity<3> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 3, _Np - 2, _Np - 1> {}; };
|
||||||
|
template<> struct __parity<4> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
|
||||||
|
template<> struct __parity<5> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
|
||||||
|
template<> struct __parity<6> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
|
||||||
|
template<> struct __parity<7> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 7, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
|
||||||
|
|
||||||
|
template<typename _Tp, typename _Up> struct __convert {
|
||||||
|
template<typename> struct __result;
|
||||||
|
template<_Tp ..._Np> struct __result<integer_sequence<_Tp, _Np...> > { typedef integer_sequence<_Up, _Np...> type; };
|
||||||
};
|
};
|
||||||
|
template<typename _Tp> struct __convert<_Tp, _Tp> { template<typename _Up> struct __result { typedef _Up type; }; };
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked =
|
||||||
|
typename __detail::__convert<size_t, _Tp>::template __result<typename __detail::__make<_Np>::type>::type;
|
||||||
|
|
||||||
template <class _Tp, _Tp _Ep>
|
template <class _Tp, _Tp _Ep>
|
||||||
struct __make_integer_sequence
|
struct __make_integer_sequence
|
||||||
@ -644,10 +671,7 @@ struct __make_integer_sequence
|
|||||||
static_assert(is_integral<_Tp>::value,
|
static_assert(is_integral<_Tp>::value,
|
||||||
"std::make_integer_sequence can only be instantiated with an integral type" );
|
"std::make_integer_sequence can only be instantiated with an integral type" );
|
||||||
static_assert(0 <= _Ep, "std::make_integer_sequence input shall not be negative");
|
static_assert(0 <= _Ep, "std::make_integer_sequence input shall not be negative");
|
||||||
typedef typename __make_integer_sequence_unchecked
|
typedef __make_integer_sequence_unchecked<_Tp, _Ep> type;
|
||||||
<
|
|
||||||
_Tp, 0, _Ep, integer_sequence<_Tp>
|
|
||||||
>::type type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class _Tp, _Tp _Np>
|
template<class _Tp, _Tp _Np>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user