Navigation
API > API/Runtime > API/Runtime/Core
Description
Returns a range which allows iteration over multiple ranges in parallel, that is, the first element from each range is returned, followed by the second elmeent from each range, followed by the third etc. This is similar to std::views::zip.
The 'element type' of the zipped range is a tuple of references into each container.
The constness of the references into each container will match the constness of the references returned by the original container, and the constness of the tuple is irrelevant. AsConst can be used with a container (not view) to return const iterators. UE::Zip supports mixing const and non-const ranges, and will 'lifetime extend' rvalue containers by taking ownership of them.
The zipped range is as long as the first range argument, and it is undefined behaviour to have a first range which is longer than any of the others being zipped.
Examples:
// Iteration: // { ContainerOfInts[0], AsConst(ContainerOfStrings)[0] } // { ContainerOfInts[1], AsConst(ContainerOfStrings)[1] } // { ContainerOfInts[2], AsConst(ContainerOfStrings)[2] } // ... for (const auto& Pair : UE::Zip(ContainerOfInts, AsConst(ContainerOfStrings))) { int32& Int = Pair.Get<0>(); const FString& Str = Pair.Get<1>(); }
Sort Array1, Array2 and Array3 in parallel by the elements in Array2 Algo::SortBy(UE::Zip(Container1, Container2), GetElementByIndex<1>);
| Name | UE::Zip |
| Type | function |
| Header File | /Engine/Source/Runtime/Core/Public/Misc/Zip.h |
| Include Path | #include "Misc/Zip.h" |
namespace UE
{
template<typename Range0Type, typename... OtherRangeTypes>
auto UE::Zip
(
Range0Type && Range0,
OtherRangeTypes &&... OtherRanges
)
}