diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-12-25 17:35:41 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2024-04-06 20:13:06 +0000 |
commit | cb14a3fe5122c879eae1fb480ed7ce82a699ddb6 (patch) | |
tree | b983a613c35ece61d561b5a9ef9cd66419f6c7fb /contrib/llvm-project/libcxx/include/__utility/integer_sequence.h | |
parent | 3d68ee6cbdb244de9fab1df8a2525d2fa592571e (diff) | |
parent | 99aabd70801bd4bc72c4942747f6d62c675112f5 (diff) |
Diffstat (limited to 'contrib/llvm-project/libcxx/include/__utility/integer_sequence.h')
-rw-r--r-- | contrib/llvm-project/libcxx/include/__utility/integer_sequence.h | 104 |
1 files changed, 51 insertions, 53 deletions
diff --git a/contrib/llvm-project/libcxx/include/__utility/integer_sequence.h b/contrib/llvm-project/libcxx/include/__utility/integer_sequence.h index bae8c241ef5a..e63f3f265b7d 100644 --- a/contrib/llvm-project/libcxx/include/__utility/integer_sequence.h +++ b/contrib/llvm-project/libcxx/include/__utility/integer_sequence.h @@ -19,7 +19,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD -template <size_t...> struct __tuple_indices; +template <size_t...> +struct __tuple_indices; template <class _IdxType, _IdxType... _Values> struct __integer_sequence { @@ -34,22 +35,28 @@ struct __integer_sequence { namespace __detail { -template<typename _Tp, size_t ..._Extra> struct __repeat; -template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<__integer_sequence<_Tp, _Np...>, _Extra...> { - typedef _LIBCPP_NODEBUG __integer_sequence<_Tp, - _Np..., - sizeof...(_Np) + _Np..., - 2 * sizeof...(_Np) + _Np..., - 3 * sizeof...(_Np) + _Np..., - 4 * sizeof...(_Np) + _Np..., - 5 * sizeof...(_Np) + _Np..., - 6 * sizeof...(_Np) + _Np..., - 7 * sizeof...(_Np) + _Np..., - _Extra...> type; +template <typename _Tp, size_t... _Extra> +struct __repeat; +template <typename _Tp, _Tp... _Np, size_t... _Extra> +struct __repeat<__integer_sequence<_Tp, _Np...>, _Extra...> { + typedef _LIBCPP_NODEBUG __integer_sequence< + _Tp, + _Np..., + sizeof...(_Np) + _Np..., + 2 * sizeof...(_Np) + _Np..., + 3 * sizeof...(_Np) + _Np..., + 4 * sizeof...(_Np) + _Np..., + 5 * sizeof...(_Np) + _Np..., + 6 * sizeof...(_Np) + _Np..., + 7 * sizeof...(_Np) + _Np..., + _Extra...> + type; }; -template<size_t _Np> struct __parity; -template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {}; +template <size_t _Np> +struct __parity; +template <size_t _Np> +struct __make : __parity<_Np % 8>::template __pmake<_Np> {}; // clang-format off template<> struct __make<0> { typedef __integer_sequence<size_t> type; }; @@ -71,80 +78,71 @@ template<> struct __parity<6> { template<size_t _Np> struct __pmake : __repeat<t 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> {}; }; // clang-format on -} // namespace detail +} // namespace __detail #endif #if __has_builtin(__make_integer_seq) template <size_t _Ep, size_t _Sp> using __make_indices_imp = - typename __make_integer_seq<__integer_sequence, size_t, _Ep - _Sp>::template - __to_tuple_indices<_Sp>; + typename __make_integer_seq<__integer_sequence, size_t, _Ep - _Sp>::template __to_tuple_indices<_Sp>; #else template <size_t _Ep, size_t _Sp> -using __make_indices_imp = - typename __detail::__make<_Ep - _Sp>::type::template __to_tuple_indices<_Sp>; +using __make_indices_imp = typename __detail::__make<_Ep - _Sp>::type::template __to_tuple_indices<_Sp>; #endif #if _LIBCPP_STD_VER >= 14 -template<class _Tp, _Tp... _Ip> -struct _LIBCPP_TEMPLATE_VIS 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_HIDE_FROM_ABI - constexpr - size_t - size() noexcept { return sizeof...(_Ip); } +template <class _Tp, _Tp... _Ip> +struct _LIBCPP_TEMPLATE_VIS 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_HIDE_FROM_ABI constexpr size_t size() noexcept { return sizeof...(_Ip); } }; -template<size_t... _Ip> - using index_sequence = integer_sequence<size_t, _Ip...>; +template <size_t... _Ip> +using index_sequence = integer_sequence<size_t, _Ip...>; -#if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE) +# if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE) template <class _Tp, _Tp _Ep> using __make_integer_sequence _LIBCPP_NODEBUG = __make_integer_seq<integer_sequence, _Tp, _Ep>; -#else +# else -template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked _LIBCPP_NODEBUG = - typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>; +template <typename _Tp, _Tp _Np> +using __make_integer_sequence_unchecked _LIBCPP_NODEBUG = + typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>; template <class _Tp, _Tp _Ep> -struct __make_integer_sequence_checked -{ - 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 must have a non-negative sequence length"); - // Workaround GCC bug by preventing bad installations when 0 <= _Ep - // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929 - typedef _LIBCPP_NODEBUG __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type; +struct __make_integer_sequence_checked { + 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 must have a non-negative sequence length"); + // Workaround GCC bug by preventing bad installations when 0 <= _Ep + // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929 + typedef _LIBCPP_NODEBUG __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type; }; template <class _Tp, _Tp _Ep> using __make_integer_sequence _LIBCPP_NODEBUG = typename __make_integer_sequence_checked<_Tp, _Ep>::type; -#endif +# endif -template<class _Tp, _Tp _Np> - using make_integer_sequence = __make_integer_sequence<_Tp, _Np>; +template <class _Tp, _Tp _Np> +using make_integer_sequence = __make_integer_sequence<_Tp, _Np>; -template<size_t _Np> - using make_index_sequence = make_integer_sequence<size_t, _Np>; +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)>; +template <class... _Tp> +using index_sequence_for = make_index_sequence<sizeof...(_Tp)>; # if _LIBCPP_STD_VER >= 20 // Executes __func for every element in an index_sequence. template <size_t... _Index, class _Function> _LIBCPP_HIDE_FROM_ABI constexpr void __for_each_index_sequence(index_sequence<_Index...>, _Function __func) { - (__func.template operator()<_Index>(), ...); + (__func.template operator()<_Index>(), ...); } # endif // _LIBCPP_STD_VER >= 20 |