#pragma once #include #include namespace NYT { //////////////////////////////////////////////////////////////////////////////// namespace NDetail { template struct TRangeToTag { }; } // namespace NDetail //////////////////////////////////////////////////////////////////////////////// //! An equivalent of Python's `zip()`, but resulting range consists of tuples //! of pointers and has length equal to the length of the shortest container. //! Implementation with mutable references depends on "lifetime extension in //! range-based for loops" from C++23. template auto ZipMutable(TRanges&&... ranges); //! Converts the provided range to the specified container. //! This is a simplified equivalent of std::ranges::to from ranges-v3. template auto RangeTo(TRange&& range); //! Range to for monadic operations template constexpr auto RangeTo(); //! Monadic operations to use RangeTo. Example: //! auto filteredHashSet = vec | std::views::filter(pred) | RangeTo>(); template auto operator|(TRange&& range, NDetail::TRangeToTag); //! Converts a parameter pack into the specified container. //! Useful for constructing containers of move-only types. //! Note that `std::vector{std::move(a), std::move(b)}` //! will not compile since std::initializer_list has only const iterators. //! However, `StaticRangeTo>(std::move(a), std::move(b))` will work. template requires (std::constructible_from && ...) TContainer StaticRangeTo(TValues... values); //! A tuple wrapper with implicit casts to containers via `StaticRangeTo`. //! Useful for container list-initialization e.g. `std::vector foo = TStaticRange{std::move(bar)};`. template struct TStaticRange; //! Shortcut for `RangeTo(std::ranges::views::transform)`. template auto TransformRangeTo(TRange&& range, TTransformFunction&& function); //! An equivalent of std::ranges::fold_left from ranges-v3. template auto FoldRange(TRange&& range, TOperation operation, TProjection projection = {}); //////////////////////////////////////////////////////////////////////////////// } // namespace NYT #define RANGE_HELPERS_INL_H_ #include "range_helpers-inl.h" #undef RANGE_HELPERS_INL_H_