Remove recursion from tuple

This commit is contained in:
sha512sum 2024-02-28 20:53:02 +00:00
parent f8a4d388c5
commit e6f988f320

View file

@ -17,20 +17,15 @@ struct TupleLeaf {
inline constexpr bool operator==(const TupleLeaf&) const = default; inline constexpr bool operator==(const TupleLeaf&) const = default;
}; };
template <std::size_t I, typename... Ts>
struct TupleHelper {
consteval TupleHelper() = default;
inline constexpr TupleHelper(const TupleHelper&) = default;
inline constexpr TupleHelper(TupleHelper&&) = default;
inline constexpr bool operator==(const TupleHelper&) const = default;
};
template <std::size_t I, typename T, typename... Ts> template <typename, typename...>
struct TupleHelper<I, T, Ts...> : public TupleLeaf<I, T> , public TupleHelper<I + 1, Ts...> { struct TupleHelper;
template <typename TT, typename... TTs>
inline constexpr TupleHelper(TT&& arg, TTs&&... args) : template <std::size_t... Is, typename... Ts>
TupleLeaf<I, T>{std::forward<TT>(arg)}, struct TupleHelper<std::index_sequence<Is...>, Ts...> : public TupleLeaf<Is, Ts>... {
TupleHelper<I + 1, Ts...>{std::forward<TTs>(args)...} {}; template <typename... TTs>
inline constexpr TupleHelper(TTs&&... args) :
TupleLeaf<Is, Ts>{std::forward<TTs>(args)}... {};
inline constexpr TupleHelper(const TupleHelper&) = default; inline constexpr TupleHelper(const TupleHelper&) = default;
inline constexpr TupleHelper(TupleHelper&&) = default; inline constexpr TupleHelper(TupleHelper&&) = default;
inline constexpr bool operator==(const TupleHelper&) const = default; inline constexpr bool operator==(const TupleHelper&) const = default;
@ -65,10 +60,10 @@ inline constexpr auto Get(T&& arg) -> decltype(get<I>(std::forward<T>(arg))) {
}; };
template <typename... Ts> template <typename... Ts>
struct Tuple : public impl::TupleHelper<0, Ts...> { struct Tuple : public impl::TupleHelper<std::index_sequence_for<Ts...>, Ts...> {
template <typename... TTs> template <typename... TTs>
inline constexpr Tuple(TTs&&... args) : inline constexpr Tuple(TTs&&... args) :
impl::TupleHelper<0, Ts...>(std::forward<TTs>(args)...) {}; impl::TupleHelper<std::index_sequence_for<Ts...>, Ts...>(std::forward<TTs>(args)...) {};
inline constexpr Tuple(const Tuple&) = default; inline constexpr Tuple(const Tuple&) = default;
inline constexpr Tuple(Tuple&&) = default; inline constexpr Tuple(Tuple&&) = default;
inline constexpr bool operator==(const Tuple&) const = default; inline constexpr bool operator==(const Tuple&) const = default;