Skip to content

Commit

Permalink
Fix min() so it can be positive
Browse files Browse the repository at this point in the history
  • Loading branch information
saraedum committed Feb 16, 2021
1 parent 36b0614 commit e683c69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/rx/ranges.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1701,8 +1701,10 @@ struct min : private Compare {
decltype(auto) input = as_input_range(std::forward<R>(range));
using range_type = decltype(input);
if (RX_LIKELY(!input.at_end())) {
type first = input.get();
input.next();
auto folder = foldl(
type{}, [this](auto&& accum, auto&& x) constexpr {
std::move(first), [this](auto&& accum, auto&& x) constexpr {
// Note: Can't use std::min(), because it takes the comparison function
// by-value.
const Compare& cmp = *this;
Expand Down
3 changes: 3 additions & 0 deletions test/test_ranges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ TEST_CASE("ranges max") {
TEST_CASE("ranges min") {
auto s = seq() | first_n(5) | min();
CHECK(*s == 0);

s = seq() | skip_n(1) | first_n(5) | min();
CHECK(*s == 1);
}

TEST_CASE("ranges infinity propagates") {
Expand Down

0 comments on commit e683c69

Please sign in to comment.