Skip to content

Commit b68449b

Browse files
Fix double dereference bug in minmax dispatches and standardize test code
1 parent a5380ac commit b68449b

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

libs/core/algorithms/include/hpx/parallel/algorithms/minmax.hpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ namespace hpx::parallel {
407407
auto smallest = it;
408408

409409
using element_type = hpx::traits::proxy_value_t<
410-
std::decay_t<decltype(HPX_INVOKE(proj, *smallest))>>;
410+
std::decay_t<hpx::util::invoke_result_t<Proj,
411+
hpx::traits::iter_reference_t<FwdIter>>>>;
411412

412413
element_type value = HPX_INVOKE(proj, *smallest);
413414
util::loop_n<std::decay_t<ExPolicy>>(
@@ -444,7 +445,9 @@ namespace hpx::parallel {
444445
auto smallest = *it;
445446

446447
using element_type = hpx::traits::proxy_value_t<
447-
std::decay_t<decltype(HPX_INVOKE(proj, *smallest))>>;
448+
std::decay_t<hpx::util::invoke_result_t<Proj,
449+
hpx::traits::iter_reference_t<typename std::
450+
iterator_traits<FwdIter>::value_type>>>>;
448451

449452
element_type value = HPX_INVOKE(proj, *smallest);
450453
util::loop_n<std::decay_t<ExPolicy>>(
@@ -476,7 +479,8 @@ namespace hpx::parallel {
476479
auto smallest = first;
477480

478481
using element_type = hpx::traits::proxy_value_t<
479-
std::decay_t<decltype(HPX_INVOKE(proj, *smallest))>>;
482+
std::decay_t<hpx::util::invoke_result_t<Proj,
483+
hpx::traits::iter_reference_t<FwdIter>>>>;
480484

481485
element_type value = HPX_INVOKE(proj, *smallest);
482486
util::loop(HPX_FORWARD(ExPolicy, policy), ++first, last,
@@ -559,7 +563,8 @@ namespace hpx::parallel {
559563
auto largest = it;
560564

561565
using element_type = hpx::traits::proxy_value_t<
562-
std::decay_t<decltype(HPX_INVOKE(proj, *largest))>>;
566+
std::decay_t<hpx::util::invoke_result_t<Proj,
567+
hpx::traits::iter_reference_t<FwdIter>>>>;
563568

564569
element_type value = HPX_INVOKE(proj, *largest);
565570
util::loop_n<std::decay_t<ExPolicy>>(
@@ -596,7 +601,9 @@ namespace hpx::parallel {
596601
auto largest = *it;
597602

598603
using element_type = hpx::traits::proxy_value_t<
599-
std::decay_t<decltype(HPX_INVOKE(proj, *largest))>>;
604+
std::decay_t<hpx::util::invoke_result_t<Proj,
605+
hpx::traits::iter_reference_t<typename std::
606+
iterator_traits<FwdIter>::value_type>>>>;
600607

601608
element_type value = HPX_INVOKE(proj, *largest);
602609
util::loop_n<std::decay_t<ExPolicy>>(
@@ -628,7 +635,8 @@ namespace hpx::parallel {
628635
auto largest = first;
629636

630637
using element_type = hpx::traits::proxy_value_t<
631-
std::decay_t<decltype(HPX_INVOKE(proj, *largest))>>;
638+
std::decay_t<hpx::util::invoke_result_t<Proj,
639+
hpx::traits::iter_reference_t<FwdIter>>>>;
632640

633641
element_type value = HPX_INVOKE(proj, *largest);
634642
util::loop(HPX_FORWARD(ExPolicy, policy), ++first, last,
@@ -711,7 +719,8 @@ namespace hpx::parallel {
711719
return result;
712720

713721
using element_type = hpx::traits::proxy_value_t<
714-
std::decay_t<decltype(HPX_INVOKE(proj, *it))>>;
722+
std::decay_t<hpx::util::invoke_result_t<Proj,
723+
hpx::traits::iter_reference_t<FwdIter>>>>;
715724

716725
element_type min_value = HPX_INVOKE(proj, *it);
717726
element_type max_value = min_value;
@@ -755,7 +764,8 @@ namespace hpx::parallel {
755764
auto result = *it;
756765

757766
using element_type = hpx::traits::proxy_value_t<
758-
std::decay_t<decltype(HPX_INVOKE(proj, *result.min))>>;
767+
std::decay_t<hpx::util::invoke_result_t<Proj,
768+
hpx::traits::iter_reference_t<Iter>>>>;
759769

760770
element_type min_value = HPX_INVOKE(proj, *result.min);
761771
element_type max_value = HPX_INVOKE(proj, *result.max);
@@ -801,7 +811,8 @@ namespace hpx::parallel {
801811
}
802812

803813
using element_type = hpx::traits::proxy_value_t<
804-
std::decay_t<decltype(HPX_INVOKE(proj, *min))>>;
814+
std::decay_t<hpx::util::invoke_result_t<Proj,
815+
hpx::traits::iter_reference_t<FwdIter>>>>;
805816

806817
element_type min_value = HPX_INVOKE(proj, *min);
807818
element_type max_value = HPX_INVOKE(proj, *max);

libs/core/algorithms/tests/unit/algorithms/minmax_element_projection.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
void test_min_element_projection()
1818
{
1919
using namespace hpx::execution;
20-
typedef std::pair<int, int> element;
20+
using element = std::pair<int, int>;
2121
std::vector<element> c = {{1, 10}, {2, 5}, {3, 15}};
2222

2323
auto proj = [](element const& p) { return p.second; };
@@ -38,7 +38,7 @@ void test_min_element_projection()
3838
void test_max_element_projection()
3939
{
4040
using namespace hpx::execution;
41-
typedef std::pair<int, int> element;
41+
using element = std::pair<int, int>;
4242
std::vector<element> c = {{1, 10}, {2, 5}, {3, 15}};
4343

4444
auto proj = [](element const& p) { return p.second; };
@@ -59,7 +59,7 @@ void test_max_element_projection()
5959
void test_minmax_element_projection()
6060
{
6161
using namespace hpx::execution;
62-
typedef std::pair<int, int> element;
62+
using element = std::pair<int, int>;
6363
std::vector<element> c = {{1, 10}, {2, 5}, {3, 15}};
6464

6565
auto proj = [](element const& p) { return p.second; };

0 commit comments

Comments
 (0)