unpack takes an n-ary function as an argument, and returns a function object which takes an n-tuple and calls the original function with the tuple arguments. It's basically a lazy version of std::apply, roughly equivalent to
It's useful when dealing with sequences whose elements are tuple-like, for example zip or cartesian_product sequences, because you can use unpack to avoid having to manually write an intermediate lambda which uses structured bindings (or std::apply) yourself, for example:
flux::cartesian_product(flux::ints(0, 10), flux::ints(0, 10))
.for_each(flux::unpack([](auto x, auto y) {
// do something with x and y coords
});
unpack
takes an n-ary function as an argument, and returns a function object which takes an n-tuple and calls the original function with the tuple arguments. It's basically a lazy version ofstd::apply
, roughly equivalent toIt's useful when dealing with sequences whose elements are tuple-like, for example
zip
orcartesian_product
sequences, because you can useunpack
to avoid having to manually write an intermediate lambda which uses structured bindings (or std::apply) yourself, for example: