[libcxx-commits] [PATCH] D117918: [libc++][test] Add const and reference tests for enable_view. NFC.

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jan 22 17:31:58 PST 2022


Quuxplusone added inline comments.


================
Comment at: libcxx/test/std/ranges/range.req/range.view/enable_view.compile.pass.cpp:46
+static_assert(!std::ranges::enable_view<EnableViewFalse&&>);
+static_assert(std::ranges::enable_view<const EnableViewFalse>);
+static_assert(!std::ranges::enable_view<const EnableViewFalse&>);
----------------
jloser wrote:
> Quuxplusone wrote:
> > philnik wrote:
> > > This seems weird. It looks to me like the standard requires it that way, but I don't know why.
> > Yikes. Good catch. This reminds me of D116388, but unlike `bind`, this stuff is so new that I think this deserves an LWG issue. I'll request one.
> Exactly my thoughts as well. It's clear from a technical perspective, but surely this isn't what the user intended. They likely intended to disable cv-qual of their type as well and expected us to do it for them basically by opting in for their type only (and not a**also**
> for cv-qual of their type).
> 
> Generally speaking, this is likely to come up with //other customization points// in the standard library, but I'd have to search for other "broken" ones.
Initial reply from LWG is: "Who cares?"

The only person who should be querying `enable_view<X>` is `concept view` itself; no user-programmer should ever be querying it. And `concept view` will care about `enable_view<X>` only when `movable<X>`, which means
- `enable_view<T&>` is never relevant
- `enable_view<const T>` is relevant only when `assignable_from<const V&, const V>`; such a `V` must have `begin()` and `end()` //and// `const V& operator=(const V&) const`.

Here are the test cases from my attempted-LWG-issue-filing, for the record.
```
  struct V1 : std::ranges::view_base {};
  struct V2 : std::ranges::view_interface<V2> {};
  struct V3 {}; template<> constexpr bool std::ranges::enable_view<V3> = true;
  struct V4 : std::view_base {}; template<> constexpr bool std::ranges::enable_view<V4> = false;

  static_assert(std::ranges::enable_view<V1> == true);
  static_assert(std::ranges::enable_view<V2> == true);
  static_assert(std::ranges::enable_view<V3> == true);
  static_assert(std::ranges::enable_view<V4> == false);

  static_assert(std::ranges::enable_view<const V1> == true);
  LIBCPP_STATIC_ASSERT(std::ranges::enable_view<const V2> == true);
  static_assert(std::ranges::enable_view<const V3> == false);
  static_assert(std::ranges::enable_view<const V4> == true);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117918



More information about the libcxx-commits mailing list