diff options
Diffstat (limited to 'libcxx/include/__utility')
-rw-r--r-- | libcxx/include/__utility/integer_sequence.h | 68 | ||||
-rw-r--r-- | libcxx/include/__utility/pair.h | 10 |
2 files changed, 32 insertions, 46 deletions
diff --git a/libcxx/include/__utility/integer_sequence.h b/libcxx/include/__utility/integer_sequence.h index d1c6e53..329826a 100644 --- a/libcxx/include/__utility/integer_sequence.h +++ b/libcxx/include/__utility/integer_sequence.h @@ -17,57 +17,41 @@ # pragma GCC system_header #endif +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_BEGIN_NAMESPACE_STD -template <size_t...> -struct __tuple_indices; +# if __has_builtin(__make_integer_seq) +template <template <class _Tp, _Tp...> class _BaseType, class _Tp, _Tp _SequenceSize> +using __make_integer_sequence_impl _LIBCPP_NODEBUG = __make_integer_seq<_BaseType, _Tp, _SequenceSize>; +# else +template <template <class _Tp, _Tp...> class _BaseType, class _Tp, _Tp _SequenceSize> +using __make_integer_sequence_impl _LIBCPP_NODEBUG = _BaseType<_Tp, __integer_pack(_SequenceSize)...>; +# endif -template <class _IdxType, _IdxType... _Values> +template <class _Tp, _Tp... _Indices> struct __integer_sequence { - template <template <class _OIdxType, _OIdxType...> class _ToIndexSeq, class _ToIndexType> - using __convert _LIBCPP_NODEBUG = _ToIndexSeq<_ToIndexType, _Values...>; - - template <size_t _Sp> - using __to_tuple_indices _LIBCPP_NODEBUG = __tuple_indices<(_Values + _Sp)...>; + using value_type = _Tp; + 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...(_Indices); } }; -#if __has_builtin(__make_integer_seq) -template <size_t _Ep, size_t _Sp> -using __make_indices_imp _LIBCPP_NODEBUG = - typename __make_integer_seq<__integer_sequence, size_t, _Ep - _Sp>::template __to_tuple_indices<_Sp>; -#elif __has_builtin(__integer_pack) -template <size_t _Ep, size_t _Sp> -using __make_indices_imp _LIBCPP_NODEBUG = - typename __integer_sequence<size_t, __integer_pack(_Ep - _Sp)...>::template __to_tuple_indices<_Sp>; -#else -# error "No known way to get an integer pack from the compiler" -#endif +template <size_t... _Indices> +using __index_sequence _LIBCPP_NODEBUG = __integer_sequence<size_t, _Indices...>; -#if _LIBCPP_STD_VER >= 14 +template <size_t _SequenceSize> +using __make_index_sequence _LIBCPP_NODEBUG = __make_integer_sequence_impl<__integer_sequence, size_t, _SequenceSize>; -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_HIDE_FROM_ABI constexpr size_t size() noexcept { return sizeof...(_Ip); } -}; +# if _LIBCPP_STD_VER >= 14 + +template <class _Tp, _Tp... _Indices> +struct integer_sequence : __integer_sequence<_Tp, _Indices...> {}; template <size_t... _Ip> using index_sequence = integer_sequence<size_t, _Ip...>; -# if __has_builtin(__make_integer_seq) - template <class _Tp, _Tp _Ep> -using make_integer_sequence _LIBCPP_NODEBUG = __make_integer_seq<integer_sequence, _Tp, _Ep>; - -# elif __has_builtin(__integer_pack) - -template <class _Tp, _Tp _SequenceSize> -using make_integer_sequence _LIBCPP_NODEBUG = integer_sequence<_Tp, __integer_pack(_SequenceSize)...>; - -# else -# error "No known way to get an integer pack from the compiler" -# endif +using make_integer_sequence _LIBCPP_NODEBUG = __make_integer_sequence_impl<integer_sequence, _Tp, _Ep>; template <size_t _Np> using make_index_sequence = make_integer_sequence<size_t, _Np>; @@ -75,16 +59,18 @@ using make_index_sequence = make_integer_sequence<size_t, _Np>; template <class... _Tp> using index_sequence_for = make_index_sequence<sizeof...(_Tp)>; -# if _LIBCPP_STD_VER >= 20 +# 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>(), ...); } -# endif // _LIBCPP_STD_VER >= 20 +# endif // _LIBCPP_STD_VER >= 20 -#endif // _LIBCPP_STD_VER >= 14 +# endif // _LIBCPP_STD_VER >= 14 _LIBCPP_END_NAMESPACE_STD +#endif // _LIBCPP_CXX03_LANG + #endif // _LIBCPP___UTILITY_INTEGER_SEQUENCE_H diff --git a/libcxx/include/__utility/pair.h b/libcxx/include/__utility/pair.h index dbacbce..33694c52 100644 --- a/libcxx/include/__utility/pair.h +++ b/libcxx/include/__utility/pair.h @@ -18,7 +18,6 @@ #include <__fwd/array.h> #include <__fwd/pair.h> #include <__fwd/tuple.h> -#include <__tuple/tuple_indices.h> #include <__tuple/tuple_like_no_subrange.h> #include <__tuple/tuple_size.h> #include <__type_traits/common_reference.h> @@ -40,6 +39,7 @@ #include <__type_traits/unwrap_ref.h> #include <__utility/declval.h> #include <__utility/forward.h> +#include <__utility/integer_sequence.h> #include <__utility/move.h> #include <__utility/piecewise_construct.h> @@ -225,8 +225,8 @@ struct pair : pair(__pc, __first_args, __second_args, - typename __make_tuple_indices<sizeof...(_Args1)>::type(), - typename __make_tuple_indices<sizeof...(_Args2) >::type()) {} + __make_index_sequence<sizeof...(_Args1)>(), + __make_index_sequence<sizeof...(_Args2)>()) {} _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair& operator=(__conditional_t<is_copy_assignable<first_type>::value && is_copy_assignable<second_type>::value, @@ -440,8 +440,8 @@ private: pair(piecewise_construct_t, tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, - __tuple_indices<_I1...>, - __tuple_indices<_I2...>) + __index_sequence<_I1...>, + __index_sequence<_I2...>) : first(std::forward<_Args1>(std::get<_I1>(__first_args))...), second(std::forward<_Args2>(std::get<_I2>(__second_args))...) {} #endif |