This is an archive of the discontinued LLVM Phabricator instance.

[libcxx][ranges] Fix `ranges::empty` when begin, end, and empty members are provided.
ClosedPublic

Authored by zoecarver on May 11 2021, 11:15 AM.

Details

Summary

Before this commit, we'd get a compilation error because the operator() overload was ambiguous.

Diff Detail

Event Timeline

zoecarver requested review of this revision.May 11 2021, 11:15 AM
zoecarver created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2021, 11:15 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript

Once the tests pass I'm going to land this.

LGTM % test comments.

libcxx/test/std/ranges/range.access/range.prim/empty.pass.cpp
136–141

As always, please unconstexpr and unbody the functions that aren't being called.

This test has its advantages (all three functions have the same const-qualification so there's no best-match stuff to take into account) but I'd like to see additionally a test with the usual const-qualifications on getters: either

struct BeginEndEmpty2 {
  int* begin();
  int* end();
  constexpr bool empty() const { return true; }
};

or

struct BeginEndEmpty2 {
  int* begin();
  int* end();
  const int* begin() const;
  const int* end() const;
  constexpr bool empty() const { return true; }
};

which would have the advantage that you could test both std::ranges::empty(x) and std::ranges::empty(std::as_const(x)) — both should return the same result.

This revision was not accepted when it landed; it landed in state Needs Review.May 13 2021, 10:08 AM
This revision was automatically updated to reflect the committed changes.