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

<algorithm>: ranges::is_permutation's helper lambda does not specify return type #2888

Closed
hewillk opened this issue Jul 20, 2022 · 0 comments · Fixed by #3113
Closed

<algorithm>: ranges::is_permutation's helper lambda does not specify return type #2888

hewillk opened this issue Jul 20, 2022 · 0 comments · Fixed by #3113
Labels
bug Something isn't working fixed Something works now, yay! ranges C++20/23 ranges

Comments

@hewillk
Copy link
Contributor

hewillk commented Jul 20, 2022

STL/stl/inc/algorithm

Lines 1010 to 1013 in ef62d3f

const auto _ProjectedPred = [&]<class _Ty1, class _Ty2>(_Ty1&& _Left, _Ty2&& _Right) {
return _STD invoke(_Pred, _STD invoke(_Proj1, _STD forward<_Ty1>(_Left)),
_STD invoke(_Proj2, _STD forward<_Ty2>(_Right)));
};

STL/stl/inc/algorithm

Lines 1099 to 1102 in ef62d3f

const auto _ProjectedPred = [&]<class _Ty1, class _Ty2>(_Ty1&& _Left, _Ty2&& _Right) {
return _STD invoke(_Pred, _STD invoke(_Proj1, _STD forward<_Ty1>(_Left)),
_STD invoke(_Proj2, _STD forward<_Ty2>(_Right)));
};

The lambda needs to specify return type eg -> bool since boolean-testable only requires that the return type of Pred can be converted to bool.

#include <algorithm>

struct Bool {
  operator bool() { return true; };
  Bool() = default;
  Bool(const Bool&) = delete;
};

int main() {
  Bool b;
  int x[] = {42};
  std::ranges::is_permutation(x, x, [&](auto, auto) -> Bool& { return b; });
}

https://godbolt.org/z/dPKKeex9o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Something works now, yay! ranges C++20/23 ranges
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants