Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ranges::is_permutation's helper lambdas #3113

Merged
merged 2 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
StephanTLavavej marked this conversation as resolved.
Show resolved Hide resolved
assert(ranges::is_permutation(range2, range2, [&](auto, auto) -> NonCopyableBool& { return b; }));
}
}
};

Expand Down