Implement n3658 - Compile-time integer sequences
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@185343 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -117,6 +117,27 @@ template<size_t I, class T1, class T2>
|
||||
typename tuple_element<I, std::pair<T1, T2> >::type&&
|
||||
get(std::pair<T1, T2>&&) noexcept;
|
||||
|
||||
// C++14
|
||||
|
||||
template<class T, T... I>
|
||||
struct integer_sequence
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
static constexpr size_t size() noexcept;
|
||||
};
|
||||
|
||||
template<size_t... I>
|
||||
using index_sequence = integer_sequence<size_t, I...>;
|
||||
|
||||
template<class T, T N>
|
||||
using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
|
||||
template<size_t N>
|
||||
using make_index_sequence = make_integer_sequence<size_t, N>;
|
||||
|
||||
template<class... T>
|
||||
using index_sequence_for = make_index_sequence<sizeof...(T)>;
|
||||
|
||||
} // std
|
||||
|
||||
*/
|
||||
@@ -578,6 +599,68 @@ get(pair<_T1, _T2>&& __p) _NOEXCEPT
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
|
||||
template<class _Tp, _Tp... _Ip>
|
||||
struct integer_sequence
|
||||
{
|
||||
typedef _Tp value_type;
|
||||
static_assert( is_integral<_Tp>::value,
|
||||
"std::integer_sequence can only be instantiated with an integral type" );
|
||||
static
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
constexpr
|
||||
size_t
|
||||
size() noexcept { return sizeof...(_Ip); }
|
||||
};
|
||||
|
||||
template<size_t... _Ip>
|
||||
using index_sequence = integer_sequence<size_t, _Ip...>;
|
||||
|
||||
template <class _Tp, _Tp _Sp, _Tp _Ep, class _IntSequence>
|
||||
struct __make_integer_sequence_unchecked;
|
||||
|
||||
template <class _Tp, _Tp _Sp, _Tp _Ep, _Tp ..._Indices>
|
||||
struct __make_integer_sequence_unchecked<_Tp, _Sp, _Ep,
|
||||
integer_sequence<_Tp, _Indices...>>
|
||||
{
|
||||
typedef typename __make_integer_sequence_unchecked
|
||||
<
|
||||
_Tp, _Sp+1, _Ep,
|
||||
integer_sequence<_Tp, _Indices..., _Sp>
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <class _Tp, _Tp _Ep, _Tp ..._Indices>
|
||||
struct __make_integer_sequence_unchecked<_Tp, _Ep, _Ep,
|
||||
integer_sequence<_Tp, _Indices...>>
|
||||
{
|
||||
typedef integer_sequence<_Tp, _Indices...> type;
|
||||
};
|
||||
|
||||
template <class _Tp, _Tp _Ep>
|
||||
struct __make_integer_sequence
|
||||
{
|
||||
static_assert(is_integral<_Tp>::value,
|
||||
"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");
|
||||
typedef typename __make_integer_sequence_unchecked
|
||||
<
|
||||
_Tp, 0, _Ep, integer_sequence<_Tp>
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template<class _Tp, _Tp _Np>
|
||||
using make_integer_sequence = typename __make_integer_sequence<_Tp, _Np>::type;
|
||||
|
||||
template<size_t _Np>
|
||||
using make_index_sequence = make_integer_sequence<size_t, _Np>;
|
||||
|
||||
template<class... _Tp>
|
||||
using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_UTILITY
|
||||
|
Reference in New Issue
Block a user