From 27aac9208152ccd61b34197f30f95e9d094a698b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=C4=8Cuki=C4=87?= Date: Tue, 19 Sep 2023 10:55:19 +0200 Subject: [PATCH] Fix typelist::at --- include/typelist.hpp | 51 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/include/typelist.hpp b/include/typelist.hpp index 186e67e6..749fb18b 100644 --- a/include/typelist.hpp +++ b/include/typelist.hpp @@ -135,6 +135,7 @@ struct splitter { template using second = typename B::template second>; }; + } // namespace detail template @@ -263,6 +264,54 @@ template typename Predicate, typename DefaultType, typename H struct find_type_or_default_impl : std::conditional_t::value, find_type_or_default_impl, find_type_or_default_impl> {}; +template +struct at_impl; + +template +struct at_impl<0, T0, Ts...> { + using type = T0; +}; + +template +struct at_impl<1, T0, T1, Ts...> { + using type = T1; +}; + +template +struct at_impl<2, T0, T1, T2, Ts...> { + using type = T2; +}; + +template +struct at_impl<3, T0, T1, T2, T3, Ts...> { + using type = T3; +}; + +template +struct at_impl<4, T0, T1, T2, T3, T4, Ts...> { + using type = T4; +}; + +template +struct at_impl<5, T0, T1, T2, T3, T4, T5, Ts...> { + using type = T5; +}; + +template +struct at_impl<6, T0, T1, T2, T3, T4, T5, T6, Ts...> { + using type = T6; +}; + +template +struct at_impl<7, T0, T1, T2, T3, T4, T5, T6, T7, Ts...> { + using type = T7; +}; + +template + requires (Index >= 8) +struct at_impl: at_impl { +}; + } // namespace detail // typelist ///////////////// @@ -292,7 +341,7 @@ struct typelist { } template - using at = first_type::template second>; + using at = detail::at_impl::type; template using prepend = typelist;