From 01c63ce606d87539f7c1365a94b18354a0dba757 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Thu, 28 Nov 2024 17:28:36 +0100 Subject: [PATCH] [oneDPL][ranges][merge] support size limit for output; + check n==0 --- include/oneapi/dpl/pstl/algorithm_ranges_impl.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/oneapi/dpl/pstl/algorithm_ranges_impl.h b/include/oneapi/dpl/pstl/algorithm_ranges_impl.h index 96cf7b2e7c..2c7d987307 100644 --- a/include/oneapi/dpl/pstl/algorithm_ranges_impl.h +++ b/include/oneapi/dpl/pstl/algorithm_ranges_impl.h @@ -448,6 +448,9 @@ auto __pattern_merge(_Tag __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _OutRange&& __out_r, _Comp __comp, _Proj1 __proj1, _Proj2 __proj2) { + using __return_type = std::ranges::merge_result, std::ranges::borrowed_iterator_t<_R2>, + std::ranges::borrowed_iterator_t<_OutRange>>; + auto __comp_2 = [__comp, __proj1, __proj2](auto&& __val1, auto&& __val2) { return std::invoke(__comp, std::invoke(__proj1, std::forward(__val1)), std::invoke(__proj2, std::forward(__val2)));}; @@ -464,10 +467,10 @@ __pattern_merge(_Tag __tag, _ExecutionPolicy&& __exec, _R1&& __r1, _R2&& __r2, _ auto __it_2 = std::ranges::begin(__r2); auto __it_out = std::ranges::begin(__out_r); - auto __res = __pattern_merge_2(__tag, std::forward<_ExecutionPolicy>(__exec), __it_2, __n_2, __it_1, __n_1, __it_out, __n_out, __comp_2); + if(__n_out == 0) + return __return_type{__it_1, __it_2, __it_out}; - using __return_type = std::ranges::merge_result, std::ranges::borrowed_iterator_t<_R2>, - std::ranges::borrowed_iterator_t<_OutRange>>; + auto __res = __pattern_merge_2(__tag, std::forward<_ExecutionPolicy>(__exec), __it_2, __n_2, __it_1, __n_1, __it_out, __n_out, __comp_2); return __return_type{__res.second, __res.first, __it_out + __n_out}; }