Skip to content

Commit

Permalink
when_all: add Sentinel support to when_all_succeed()
Browse files Browse the repository at this point in the history
Extend `when_all_succeed()` to accept ranges with heterogeneous iterator
and sentinel types by adding a separate template parameter for the sentinel.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
  • Loading branch information
tchaikov committed Dec 5, 2024
1 parent 141c807 commit 5c7dd23
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions include/seastar/core/when_all.hh
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ complete_when_all(std::vector<Future>&& futures, typename std::vector<Future>::i
});
}

template<typename ResolvedVectorTransform, typename FutureIterator>
template<typename ResolvedVectorTransform, typename FutureIterator, typename Sentinel>
inline auto
do_when_all(FutureIterator begin, FutureIterator end) noexcept {
do_when_all(FutureIterator begin, Sentinel end) noexcept {
using itraits = std::iterator_traits<FutureIterator>;
auto make_values_vector = [] (size_t size) noexcept {
memory::scoped_critical_alloc_section _;
Expand All @@ -300,7 +300,7 @@ do_when_all(FutureIterator begin, FutureIterator end) noexcept {
make_values_vector(iterator_range_estimate_vector_capacity(begin, end));
// Important to invoke the *begin here, in case it's a function iterator,
// so we launch all computation in parallel.
std::move(begin, end, std::back_inserter(ret));
std::ranges::move(begin, end, std::back_inserter(ret));
return complete_when_all<ResolvedVectorTransform>(std::move(ret), ret.begin());
}

Expand Down Expand Up @@ -508,14 +508,14 @@ inline auto when_all_succeed(FutOrFuncs&&... fut_or_funcs) noexcept {
/// \param end an \c InputIterator designating the end of the range of futures
/// \return an \c std::vector<> of all the valus in the input
SEASTAR_MODULE_EXPORT
template <typename FutureIterator, typename = typename std::iterator_traits<FutureIterator>::value_type>
template <typename FutureIterator, typename Sentinel, typename = typename std::iterator_traits<FutureIterator>::value_type>
requires requires (FutureIterator i) {
*i++;
{ i != i } -> std::convertible_to<bool>;
requires is_future<std::remove_reference_t<decltype(*i)>>::value;
}
inline auto
when_all_succeed(FutureIterator begin, FutureIterator end) noexcept {
when_all_succeed(FutureIterator begin, Sentinel end) noexcept {
using itraits = std::iterator_traits<FutureIterator>;
using result_transform = internal::extract_values_from_futures_vector<typename itraits::value_type>;
try {
Expand Down

0 comments on commit 5c7dd23

Please sign in to comment.