Skip to content

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

@hewillk

Description

@hewillk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!rangesC++20/23 ranges

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions