C++ Logo

std-proposals

Advanced search

Re: Generic variadic pack expansion utility

From: Maciej Cencora <m.cencora_at_[hidden]>
Date: Wed, 17 Jul 2019 19:43:42 +0200
There is no need for any library utilities in C++20 for that. What is more,
I think that std::index_sequence is a gross hack and should die.

With P1306 Expansion statements you can just write "normal" code:

for ... (constexpr size_t i : std::ranges::iota(0, sizeof...(Ts)))
{
    ranges::swap(std::get<i>(lhs), std::get<i>(rhs));
}

Working example here: https://cppx.godbolt.org/z/rkQEgp


And with slightly extended P1061 "Structured Bindings can introduce a Pack"
you can cover all other use-cases:
eg, simplified std::apply:

template <typename Functor, typename Tuple>
decltype(auto) apply(Functor&& func, Tuple&& tup)
{
    constexpr auto [...Ints] = std::ranges::iota(0,
std::tuple_size_v<Tuple>);
    return func(std::get<Ints>(tup)...);
}

Regards,
Maciej

Received on 2019-07-17 12:45:56