P3817 — packs

◀ back to the paper

Packs, in one line

template <typename Src, typename... Ts> void assign_from(Src&& t, Ts&... targets)

Today

std::tie(targets...) = std::move(t);                   // only if Src is a std::tuple or pair
[&]<std::size_t... Is>(std::index_sequence<Is...>) {   // otherwise, this
    ((targets = std::get<Is>(std::move(t))), ...);
}(std::index_sequence_for<Ts...>{});

With P3817

auto [using targets...] = std::move(t);

Possible usage

Given

auto [using targets...] = std::move(t);   // into a pack of variables
auto [using arr[Is]...] = std::move(t);   // into chosen elements of arr

Is is any index pack, supplied at the call — assign_into<2, 0, 1>(...). No std::index_sequence is involved.

Taken together, the expansions must produce exactly the structured binding size less the number of non-pack elements — otherwise the program is ill-formed.