Skip to content

Commit 55b4c2a

Browse files
committed
test: fix technical issue with min_element in reduce tests
1 parent 65d4112 commit 55b4c2a

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

modules/core/test/ref_reduce_arg.impl.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@
1212

1313
namespace cvtest {
1414

15+
// Standard library (technically) forbids using std::min_element
16+
// with non-strict std::less_equal, so we make our own min_element
17+
template <typename Iter, typename Comp>
18+
Iter custom_min_element(Iter begin, Iter end, Comp cmp_less)
19+
{
20+
if (begin == end)
21+
return begin;
22+
Iter result = begin;
23+
while (++begin != end)
24+
if (cmp_less(*begin, *result))
25+
result = begin;
26+
return result;
27+
}
28+
29+
1530
template <class Cmp, typename T>
1631
struct reduceMinMaxImpl
1732
{
@@ -30,7 +45,7 @@ struct reduceMinMaxImpl
3045
cv::Mat sub = src(idx);
3146

3247
auto begin = sub.begin<T>();
33-
auto it = std::min_element(begin, sub.end<T>(), cmp);
48+
auto it = custom_min_element(begin, sub.end<T>(), cmp);
3449
*dst(idx).ptr<int32_t>() = static_cast<int32_t>(std::distance(begin, it));
3550

3651
for (int j = static_cast<int>(idx.size()) - 1; j >= 0; --j)

0 commit comments

Comments
 (0)