[libcxx-commits] [PATCH] D107169: [libc++] Do not define views::all as a CPO since it isn't one

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 30 07:59:13 PDT 2021


ldionne created this revision.
ldionne requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Per http://eel.is/c++draft/range.adaptors#range.all.general-2, views::all
is a range adaptor object, but not a CPO. We don't need to define it like
a CPO to avoid name collisions with hidden friend functions of the same
name.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107169

Files:
  libcxx/include/__ranges/all.h


Index: libcxx/include/__ranges/all.h
===================================================================
--- libcxx/include/__ranges/all.h
+++ libcxx/include/__ranges/all.h
@@ -34,43 +34,39 @@
 
 namespace views {
 
-namespace __all {
-  struct __fn {
-    template<class _Tp>
-      requires ranges::view<decay_t<_Tp>>
-    _LIBCPP_HIDE_FROM_ABI
-    constexpr auto operator()(_Tp&& __t) const
-      noexcept(noexcept(_VSTD::__decay_copy(_VSTD::forward<_Tp>(__t))))
-    {
-      return _VSTD::forward<_Tp>(__t);
-    }
-
-    template<class _Tp>
-      requires (!ranges::view<decay_t<_Tp>>) &&
-               requires (_Tp&& __t) { ranges::ref_view{_VSTD::forward<_Tp>(__t)}; }
-    _LIBCPP_HIDE_FROM_ABI
-    constexpr auto operator()(_Tp&& __t) const
-      noexcept(noexcept(ranges::ref_view{_VSTD::forward<_Tp>(__t)}))
-    {
-      return ranges::ref_view{_VSTD::forward<_Tp>(__t)};
-    }
-
-    template<class _Tp>
-      requires (!ranges::view<decay_t<_Tp>> &&
-                !requires (_Tp&& __t) { ranges::ref_view{_VSTD::forward<_Tp>(__t)}; } &&
-                 requires (_Tp&& __t) { ranges::subrange{_VSTD::forward<_Tp>(__t)}; })
-    _LIBCPP_HIDE_FROM_ABI
-    constexpr auto operator()(_Tp&& __t) const
-      noexcept(noexcept(ranges::subrange{_VSTD::forward<_Tp>(__t)}))
-    {
-      return ranges::subrange{_VSTD::forward<_Tp>(__t)};
-    }
-  };
-}
-
-inline namespace __cpo {
-  inline constexpr auto all = __all::__fn{};
-} // namespace __cpo
+struct __all_adaptor {
+  template<class _Tp>
+    requires ranges::view<decay_t<_Tp>>
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr auto operator()(_Tp&& __t) const
+    noexcept(noexcept(_VSTD::__decay_copy(_VSTD::forward<_Tp>(__t))))
+  {
+    return _VSTD::forward<_Tp>(__t);
+  }
+
+  template<class _Tp>
+    requires (!ranges::view<decay_t<_Tp>>) &&
+              requires (_Tp&& __t) { ranges::ref_view{_VSTD::forward<_Tp>(__t)}; }
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr auto operator()(_Tp&& __t) const
+    noexcept(noexcept(ranges::ref_view{_VSTD::forward<_Tp>(__t)}))
+  {
+    return ranges::ref_view{_VSTD::forward<_Tp>(__t)};
+  }
+
+  template<class _Tp>
+    requires (!ranges::view<decay_t<_Tp>> &&
+              !requires (_Tp&& __t) { ranges::ref_view{_VSTD::forward<_Tp>(__t)}; } &&
+                requires (_Tp&& __t) { ranges::subrange{_VSTD::forward<_Tp>(__t)}; })
+  _LIBCPP_HIDE_FROM_ABI
+  constexpr auto operator()(_Tp&& __t) const
+    noexcept(noexcept(ranges::subrange{_VSTD::forward<_Tp>(__t)}))
+  {
+    return ranges::subrange{_VSTD::forward<_Tp>(__t)};
+  }
+};
+
+inline constexpr auto all = __all_adaptor{};
 
 template<ranges::viewable_range _Range>
 using all_t = decltype(views::all(declval<_Range>()));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107169.363095.patch
Type: text/x-patch
Size: 2716 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210730/d3b90e01/attachment.bin>


More information about the libcxx-commits mailing list