[libcxx-commits] [PATCH] D102263: [libcxx][ranges] Fix `ranges::empty` when begin, end, and empty members are provided.

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue May 11 11:28:49 PDT 2021


Quuxplusone added a comment.

LGTM % test comments.



================
Comment at: libcxx/test/std/ranges/range.access/range.prim/empty.pass.cpp:136-141
+struct BeginEndAndEmpty {
+  int buff[8];
+  constexpr int* begin() { return buff; }
+  constexpr int* end() { return buff + 8; }
+  constexpr bool empty() { return true; }
+};
----------------
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.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102263/new/

https://reviews.llvm.org/D102263



More information about the libcxx-commits mailing list