[libcxx-commits] [PATCH] D101193: [libcxx][ranges] Add ranges::empty CPO.

Tim Song via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu May 6 15:31:43 PDT 2021


tcanens added inline comments.


================
Comment at: libcxx/include/__ranges/empty.h:48
+
+  struct __fn {
+    template <__member_empty _Tp>
----------------
Quuxplusone wrote:
> tcanens wrote:
> > Quuxplusone wrote:
> > > Doesn't clearly implement a case corresponding to the bullet point ["If `T` is an array of unknown bound, `ranges​::​empty(E)` is ill-formed."](https://eel.is/c++draft/range.access#range.prim.empty-2.1)
> > > But I think that bullet point is actually redundant; arrays of unknown bound also don't have `ranges::end(E)` or `ranges::size(E)` or `t.begin()`.
> > > Do we understand the intent (in all these CPOs) when `T` is a //reference to// an array of unknown bound?
> > > Doesn't clearly implement a case corresponding to the bullet point ["If `T` is an array of unknown bound, `ranges​::​empty(E)` is ill-formed."](https://eel.is/c++draft/range.access#range.prim.empty-2.1)
> > > But I think that bullet point is actually redundant; arrays of unknown bound also don't have `ranges::end(E)` or `ranges::size(E)` or `t.begin()`.
> > 
> > The difference is that for array of unknown bound of incomplete type, `ranges::begin` / `ranges::end` are IFNDR, but `ranges::empty` is ill-formed DR.
> > 
> > > Do we understand the intent (in all these CPOs) when `T` is a //reference to// an array of unknown bound?
> > 
> > `T` is the type of some expression. Expressions don't have reference type.
> @tcanens: "Expressions don't have reference type" — What if `T` is the type of the expression `foo()`, where `foo` is declared as `int (&foo())[]`? Wouldn't `foo()` have reference type then? Or would you simply say it has type "array of unknown bound" and is an lvalue?
> Anyway, libstdc++ and MSVC both agree that in that case `ranges::empty` should SFINAE away, which is the expected/simple/obvious answer anyway.
>  Or would you simply say it has type "array of unknown bound" and is an lvalue?

This. See [expr.type]/1.


================
Comment at: libcxx/test/std/ranges/range.access/range.prim/empty.pass.cpp:25
+
+static_assert(!std::is_invocable_v<RangeEmptyT, int[]>);
+static_assert( std::is_invocable_v<RangeEmptyT, int[1]>);
----------------
Quuxplusone wrote:
> Add:
> ```
> static_assert(!std::is_invocable_v<RangeEmptyT, int(&)[]>);
> static_assert(!std::is_invocable_v<RangeEmptyT, int(&&)[]>);
> ```
I'd suggest a test case for "array of unknown bound of incomplete type" (ideally for all the ranges CPOs). We spent a decent chunk of time in LWG pinning down what should happen for those.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101193



More information about the libcxx-commits mailing list