diff --git a/include/rx/ranges.hpp b/include/rx/ranges.hpp index b18b334..116e818 100644 --- a/include/rx/ranges.hpp +++ b/include/rx/ranges.hpp @@ -1701,8 +1701,10 @@ struct min : private Compare { decltype(auto) input = as_input_range(std::forward(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; diff --git a/test/test_ranges.cpp b/test/test_ranges.cpp index 7339569..6f6c227 100644 --- a/test/test_ranges.cpp +++ b/test/test_ranges.cpp @@ -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") {