Skip to content

Commit

Permalink
Fix ranges::is_permutation's helper lambdas (microsoft#3113)
Browse files Browse the repository at this point in the history
Co-authored-by: Casey Carter <cartec69@gmail.com>
  • Loading branch information
JMazurkiewicz and CaseyCarter committed Oct 6, 2022
1 parent d2c242d commit 787eb80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stl/inc/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ namespace ranges {
// We've trimmed matching prefixes and matching suffixes.
// Now we need to compare each range's prefix to the other range's suffix.

const auto _ProjectedPred = [&]<class _Ty1, class _Ty2>(_Ty1&& _Left, _Ty2&& _Right) {
const auto _ProjectedPred = [&]<class _Ty1, class _Ty2>(_Ty1&& _Left, _Ty2&& _Right) -> bool {
return _STD invoke(_Pred, _STD invoke(_Proj1, _STD forward<_Ty1>(_Left)),
_STD invoke(_Proj2, _STD forward<_Ty2>(_Right)));
};
Expand Down Expand Up @@ -1046,7 +1046,7 @@ namespace ranges {
// We've trimmed matching prefixes and matching suffixes.
// Now we need to compare each range's prefix to the other range's suffix.

const auto _ProjectedPred = [&]<class _Ty1, class _Ty2>(_Ty1&& _Left, _Ty2&& _Right) {
const auto _ProjectedPred = [&]<class _Ty1, class _Ty2>(_Ty1&& _Left, _Ty2&& _Right) -> bool {
return _STD invoke(_Pred, _STD invoke(_Proj1, _STD forward<_Ty1>(_Left)),
_STD invoke(_Proj2, _STD forward<_Ty2>(_Right)));
};
Expand Down
11 changes: 11 additions & 0 deletions tests/std/tests/P0896R4_ranges_alg_is_permutation/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ struct instantiator {
assert(ranges::is_permutation(
r1, r2, {}, [](int n) { return n + 1; }, [](int n) { return n - 1; }));
}
{ // Test GH-2888: `<algorithm>`: `ranges::is_permutation`'s helper lambda does not specify return type
struct NonCopyableBool {
constexpr operator bool() {
return true;
}

NonCopyableBool() = default;
NonCopyableBool(const NonCopyableBool&) = delete;
} b;
assert(ranges::is_permutation(range2, range2, [&](auto, auto) -> NonCopyableBool& { return b; }));
}
}
};

Expand Down

0 comments on commit 787eb80

Please sign in to comment.