[libcxx-commits] [libcxx] 56b447e - [libc++] Rename transform_view::{__iterator, __sentinel} to __transform_view_{iterator, sentinel}

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jan 11 11:45:00 PST 2023


Author: Nikolas Klauser
Date: 2023-01-11T20:44:54+01:00
New Revision: 56b447e482d668394e7ffa677c52694d48ec58ca

URL: https://github.com/llvm/llvm-project/commit/56b447e482d668394e7ffa677c52694d48ec58ca
DIFF: https://github.com/llvm/llvm-project/commit/56b447e482d668394e7ffa677c52694d48ec58ca.diff

LOG: [libc++] Rename transform_view::{__iterator, __sentinel} to __transform_view_{iterator, sentinel}

This makes it a lot easier to specialize traits types, like __segmented_iterator_traits.

Reviewed By: var-const, #libc

Spies: libcxx-commits

Differential Revision: https://reviews.llvm.org/D140728

Added: 
    

Modified: 
    libcxx/include/__ranges/transform_view.h

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__ranges/transform_view.h b/libcxx/include/__ranges/transform_view.h
index 0b5ced3df428..66d9e80e6e61 100644
--- a/libcxx/include/__ranges/transform_view.h
+++ b/libcxx/include/__ranges/transform_view.h
@@ -57,11 +57,31 @@ concept __transform_view_constraints =
   regular_invocable<_Fn&, range_reference_t<_View>> &&
   __can_reference<invoke_result_t<_Fn&, range_reference_t<_View>>>;
 
+template <input_range _View, copy_constructible _Function, bool _IsConst>
+  requires __transform_view_constraints<_View, _Function>
+class __transform_view_iterator;
+
+template <input_range _View, copy_constructible _Function, bool _IsConst>
+  requires __transform_view_constraints<_View, _Function>
+class __transform_view_sentinel;
+
 template<input_range _View, copy_constructible _Fn>
   requires __transform_view_constraints<_View, _Fn>
 class transform_view : public view_interface<transform_view<_View, _Fn>> {
-  template<bool> class __iterator;
-  template<bool> class __sentinel;
+
+  template <bool _IsConst>
+  using __iterator = __transform_view_iterator<_View, _Fn, _IsConst>;
+
+  template <bool _IsConst>
+  using __sentinel = __transform_view_sentinel<_View, _Fn, _IsConst>;
+
+  template <input_range _ViewType, copy_constructible _FunctionType, bool _IsConst>
+    requires __transform_view_constraints<_ViewType, _FunctionType>
+  friend class __transform_view_iterator;
+
+  template <input_range _ViewType, copy_constructible _FunctionType, bool _IsConst>
+    requires __transform_view_constraints<_ViewType, _FunctionType>
+  friend class __transform_view_sentinel;
 
   _LIBCPP_NO_UNIQUE_ADDRESS __copyable_box<_Fn> __func_;
   _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
@@ -156,22 +176,23 @@ struct __transform_view_iterator_category_base<_View, _Fn> {
   >;
 };
 
-template<input_range _View, copy_constructible _Fn>
+template<input_range _View, copy_constructible _Fn, bool _Const>
   requires __transform_view_constraints<_View, _Fn>
-template<bool _Const>
-class transform_view<_View, _Fn>::__iterator
+class __transform_view_iterator
   : public __transform_view_iterator_category_base<_View, _Fn> {
 
-  using _Parent = __maybe_const<_Const, transform_view>;
+  using _Parent = __maybe_const<_Const, transform_view<_View, _Fn>>;
   using _Base = __maybe_const<_Const, _View>;
 
   _Parent *__parent_ = nullptr;
 
-  template<bool>
-  friend class transform_view<_View, _Fn>::__iterator;
+  template<input_range _ViewType, copy_constructible _FunctionType, bool _IsConst>
+    requires __transform_view_constraints<_ViewType, _FunctionType>
+  friend class __transform_view_iterator;
 
-  template<bool>
-  friend class transform_view<_View, _Fn>::__sentinel;
+  template<input_range _ViewType, copy_constructible _FunctionType, bool _IsConst>
+    requires __transform_view_constraints<_ViewType, _FunctionType>
+  friend class __transform_view_sentinel;
 
 public:
   iterator_t<_Base> __current_ = iterator_t<_Base>();
@@ -181,17 +202,17 @@ class transform_view<_View, _Fn>::__iterator
   using 
diff erence_type = range_
diff erence_t<_Base>;
 
   _LIBCPP_HIDE_FROM_ABI
-  __iterator() requires default_initializable<iterator_t<_Base>> = default;
+  __transform_view_iterator() requires default_initializable<iterator_t<_Base>> = default;
 
   _LIBCPP_HIDE_FROM_ABI
-  constexpr __iterator(_Parent& __parent, iterator_t<_Base> __current)
+  constexpr __transform_view_iterator(_Parent& __parent, iterator_t<_Base> __current)
     : __parent_(std::addressof(__parent)), __current_(std::move(__current)) {}
 
-  // Note: `__i` should always be `__iterator<false>`, but directly using
-  // `__iterator<false>` is ill-formed when `_Const` is false
+  // Note: `__i` should always be `__transform_view_iterator<false>`, but directly using
+  // `__transform_view_iterator<false>` is ill-formed when `_Const` is false
   // (see http://wg21.link/class.copy.ctor#5).
   _LIBCPP_HIDE_FROM_ABI
-  constexpr __iterator(__iterator<!_Const> __i)
+  constexpr __transform_view_iterator(__transform_view_iterator<_View, _Fn, !_Const> __i)
     requires _Const && convertible_to<iterator_t<_View>, iterator_t<_Base>>
     : __parent_(__i.__parent_), __current_(std::move(__i.__current_)) {}
 
@@ -213,7 +234,7 @@ class transform_view<_View, _Fn>::__iterator
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  constexpr __iterator& operator++() {
+  constexpr __transform_view_iterator& operator++() {
     ++__current_;
     return *this;
   }
@@ -222,7 +243,7 @@ class transform_view<_View, _Fn>::__iterator
   constexpr void operator++(int) { ++__current_; }
 
   _LIBCPP_HIDE_FROM_ABI
-  constexpr __iterator operator++(int)
+  constexpr __transform_view_iterator operator++(int)
     requires forward_range<_Base>
   {
     auto __tmp = *this;
@@ -231,7 +252,7 @@ class transform_view<_View, _Fn>::__iterator
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  constexpr __iterator& operator--()
+  constexpr __transform_view_iterator& operator--()
     requires bidirectional_range<_Base>
   {
     --__current_;
@@ -239,7 +260,7 @@ class transform_view<_View, _Fn>::__iterator
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  constexpr __iterator operator--(int)
+  constexpr __transform_view_iterator operator--(int)
     requires bidirectional_range<_Base>
   {
     auto __tmp = *this;
@@ -248,7 +269,7 @@ class transform_view<_View, _Fn>::__iterator
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  constexpr __iterator& operator+=(
diff erence_type __n)
+  constexpr __transform_view_iterator& operator+=(
diff erence_type __n)
     requires random_access_range<_Base>
   {
     __current_ += __n;
@@ -256,7 +277,7 @@ class transform_view<_View, _Fn>::__iterator
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  constexpr __iterator& operator-=(
diff erence_type __n)
+  constexpr __transform_view_iterator& operator-=(
diff erence_type __n)
     requires random_access_range<_Base>
   {
     __current_ -= __n;
@@ -272,77 +293,77 @@ class transform_view<_View, _Fn>::__iterator
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  friend constexpr bool operator==(const __iterator& __x, const __iterator& __y)
+  friend constexpr bool operator==(const __transform_view_iterator& __x, const __transform_view_iterator& __y)
     requires equality_comparable<iterator_t<_Base>>
   {
     return __x.__current_ == __y.__current_;
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  friend constexpr bool operator<(const __iterator& __x, const __iterator& __y)
+  friend constexpr bool operator<(const __transform_view_iterator& __x, const __transform_view_iterator& __y)
     requires random_access_range<_Base>
   {
     return __x.__current_ < __y.__current_;
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  friend constexpr bool operator>(const __iterator& __x, const __iterator& __y)
+  friend constexpr bool operator>(const __transform_view_iterator& __x, const __transform_view_iterator& __y)
     requires random_access_range<_Base>
   {
     return __x.__current_ > __y.__current_;
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  friend constexpr bool operator<=(const __iterator& __x, const __iterator& __y)
+  friend constexpr bool operator<=(const __transform_view_iterator& __x, const __transform_view_iterator& __y)
     requires random_access_range<_Base>
   {
     return __x.__current_ <= __y.__current_;
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  friend constexpr bool operator>=(const __iterator& __x, const __iterator& __y)
+  friend constexpr bool operator>=(const __transform_view_iterator& __x, const __transform_view_iterator& __y)
     requires random_access_range<_Base>
   {
     return __x.__current_ >= __y.__current_;
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  friend constexpr auto operator<=>(const __iterator& __x, const __iterator& __y)
+  friend constexpr auto operator<=>(const __transform_view_iterator& __x, const __transform_view_iterator& __y)
     requires random_access_range<_Base> && three_way_comparable<iterator_t<_Base>>
   {
     return __x.__current_ <=> __y.__current_;
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  friend constexpr __iterator operator+(__iterator __i, 
diff erence_type __n)
+  friend constexpr __transform_view_iterator operator+(__transform_view_iterator __i, 
diff erence_type __n)
     requires random_access_range<_Base>
   {
-    return __iterator{*__i.__parent_, __i.__current_ + __n};
+    return __transform_view_iterator{*__i.__parent_, __i.__current_ + __n};
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  friend constexpr __iterator operator+(
diff erence_type __n, __iterator __i)
+  friend constexpr __transform_view_iterator operator+(
diff erence_type __n, __transform_view_iterator __i)
     requires random_access_range<_Base>
   {
-    return __iterator{*__i.__parent_, __i.__current_ + __n};
+    return __transform_view_iterator{*__i.__parent_, __i.__current_ + __n};
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  friend constexpr __iterator operator-(__iterator __i, 
diff erence_type __n)
+  friend constexpr __transform_view_iterator operator-(__transform_view_iterator __i, 
diff erence_type __n)
     requires random_access_range<_Base>
   {
-    return __iterator{*__i.__parent_, __i.__current_ - __n};
+    return __transform_view_iterator{*__i.__parent_, __i.__current_ - __n};
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  friend constexpr 
diff erence_type operator-(const __iterator& __x, const __iterator& __y)
+  friend constexpr 
diff erence_type operator-(const __transform_view_iterator& __x, const __transform_view_iterator& __y)
     requires sized_sentinel_for<iterator_t<_Base>, iterator_t<_Base>>
   {
     return __x.__current_ - __y.__current_;
   }
 
   _LIBCPP_HIDE_FROM_ABI
-  friend constexpr decltype(auto) iter_move(const __iterator& __i)
+  friend constexpr decltype(auto) iter_move(const __transform_view_iterator& __i)
     noexcept(noexcept(*__i))
   {
     if constexpr (is_lvalue_reference_v<decltype(*__i)>)
@@ -352,33 +373,37 @@ class transform_view<_View, _Fn>::__iterator
   }
 };
 
-template<input_range _View, copy_constructible _Fn>
+template<input_range _View, copy_constructible _Fn, bool _Const>
   requires __transform_view_constraints<_View, _Fn>
-template<bool _Const>
-class transform_view<_View, _Fn>::__sentinel {
-  using _Parent = __maybe_const<_Const, transform_view>;
+class __transform_view_sentinel {
+  using _Parent = __maybe_const<_Const, transform_view<_View, _Fn>>;
   using _Base = __maybe_const<_Const, _View>;
 
+  template <bool _IsConst>
+  using __iterator = __transform_view_iterator<_View, _Fn, _IsConst>;
+
   sentinel_t<_Base> __end_ = sentinel_t<_Base>();
 
-  template<bool>
-  friend class transform_view<_View, _Fn>::__iterator;
+  template<input_range _ViewType, copy_constructible _FunctionType, bool _IsConst>
+    requires __transform_view_constraints<_ViewType, _FunctionType>
+  friend class __transform_view_iterator;
 
-  template<bool>
-  friend class transform_view<_View, _Fn>::__sentinel;
+  template<input_range _ViewType, copy_constructible _FunctionType, bool _IsConst>
+    requires __transform_view_constraints<_ViewType, _FunctionType>
+  friend class __transform_view_sentinel;
 
 public:
   _LIBCPP_HIDE_FROM_ABI
-  __sentinel() = default;
+  __transform_view_sentinel() = default;
 
   _LIBCPP_HIDE_FROM_ABI
-  constexpr explicit __sentinel(sentinel_t<_Base> __end) : __end_(__end) {}
+  constexpr explicit __transform_view_sentinel(sentinel_t<_Base> __end) : __end_(__end) {}
 
-  // Note: `__i` should always be `__sentinel<false>`, but directly using
-  // `__sentinel<false>` is ill-formed when `_Const` is false
+  // Note: `__i` should always be `__transform_view_sentinel<false>`, but directly using
+  // `__transform_view_sentinel<false>` is ill-formed when `_Const` is false
   // (see http://wg21.link/class.copy.ctor#5).
   _LIBCPP_HIDE_FROM_ABI
-  constexpr __sentinel(__sentinel<!_Const> __i)
+  constexpr __transform_view_sentinel(__transform_view_sentinel<_View, _Fn, !_Const> __i)
     requires _Const && convertible_to<sentinel_t<_View>, sentinel_t<_Base>>
     : __end_(std::move(__i.__end_)) {}
 
@@ -388,7 +413,7 @@ class transform_view<_View, _Fn>::__sentinel {
   template<bool _OtherConst>
     requires sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
   _LIBCPP_HIDE_FROM_ABI
-  friend constexpr bool operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) {
+  friend constexpr bool operator==(const __iterator<_OtherConst>& __x, const __transform_view_sentinel& __y) {
     return __x.__current_ == __y.__end_;
   }
 
@@ -396,7 +421,7 @@ class transform_view<_View, _Fn>::__sentinel {
     requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
   _LIBCPP_HIDE_FROM_ABI
   friend constexpr range_
diff erence_t<__maybe_const<_OtherConst, _View>>
-  operator-(const __iterator<_OtherConst>& __x, const __sentinel& __y) {
+  operator-(const __iterator<_OtherConst>& __x, const __transform_view_sentinel& __y) {
     return __x.__current_ - __y.__end_;
   }
 
@@ -404,7 +429,7 @@ class transform_view<_View, _Fn>::__sentinel {
     requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>>
   _LIBCPP_HIDE_FROM_ABI
   friend constexpr range_
diff erence_t<__maybe_const<_OtherConst, _View>>
-  operator-(const __sentinel& __x, const __iterator<_OtherConst>& __y) {
+  operator-(const __transform_view_sentinel& __x, const __iterator<_OtherConst>& __y) {
     return __x.__end_ - __y.__current_;
   }
 };


        


More information about the libcxx-commits mailing list