public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Use alias template for iterator_category [PR110970]
@ 2023-08-10 22:32 Jonathan Wakely
  2023-08-11  0:03 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2023-08-10 22:32 UTC (permalink / raw)
  To: libstdc++, gcc-patches

Tested x86_64-linux. Pushed to trunk. Backport to gcc-13 to follow.

-- >8 --

This renames __iterator_category_t to __iter_category_t, for consistency
with std::iter_value_t, std::iter_difference_t and std::iter_reference_t
in C++20. Then use __iter_category_t in <bits/stl_iterator.h>, which
fixes the problem of the missing 'typename' that Clang 15 incorrectly
still requires.

libstdc++-v3/ChangeLog:

	PR libstdc++/110970
	* include/bits/stl_iterator.h (__detail::__move_iter_cat): Use
	__iter_category_t.
	(iterator_traits<common_iterator<I, S>>::_S_iter_cat): Likewise.
	(__detail::__basic_const_iterator_iter_cat): Likewise.
	* include/bits/stl_iterator_base_types.h (__iterator_category_t):
	Rename to __iter_category_t.
---
 libstdc++-v3/include/bits/stl_iterator.h        | 17 +++++++++--------
 .../include/bits/stl_iterator_base_types.h      |  6 +++---
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h
index b22d9a4fdb3..d5ba05f3e22 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -103,6 +103,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       using __clamp_iter_cat
 	= __conditional_t<derived_from<_Cat, _Limit>, _Limit, _Otherwise>;
 
+    template<typename _Iter, typename _Limit>
+      using __clamped_iter_cat_t
+	= __clamp_iter_cat<__iter_category_t<_Iter>, _Limit>;
+
     template<typename _Tp, typename _Up>
       concept __different_from
 	= !same_as<remove_cvref_t<_Tp>, remove_cvref_t<_Up>>;
@@ -168,8 +172,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 			  random_access_iterator_tag,
 			  bidirectional_iterator_tag>;
       using iterator_category
-	= __detail::__clamp_iter_cat<typename __traits_type::iterator_category,
-				     random_access_iterator_tag>;
+	= __detail::__clamped_iter_cat_t<_Iterator, random_access_iterator_tag>;
       using value_type = iter_value_t<_Iterator>;
       using difference_type = iter_difference_t<_Iterator>;
       using reference = iter_reference_t<_Iterator>;
@@ -1426,12 +1429,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       { };
 
     template<typename _Iterator>
-      requires requires { typename iterator_traits<_Iterator>::iterator_category; }
+      requires requires { typename __iter_category_t<_Iterator>; }
       struct __move_iter_cat<_Iterator>
       {
 	using iterator_category
-	  = __clamp_iter_cat<typename iterator_traits<_Iterator>::iterator_category,
-			     random_access_iterator_tag>;
+	  = __clamped_iter_cat_t<_Iterator, random_access_iterator_tag>;
       };
 #endif
   }
@@ -2288,8 +2290,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       static auto
       _S_iter_cat()
       {
-	using _Traits = iterator_traits<_It>;
-	if constexpr (requires { requires derived_from<typename _Traits::iterator_category,
+	if constexpr (requires { requires derived_from<__iter_category_t<_It>,
 						       forward_iterator_tag>; })
 	  return forward_iterator_tag{};
 	else
@@ -2615,7 +2616,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
     template<forward_iterator _It>
       struct __basic_const_iterator_iter_cat<_It>
-      { using iterator_category = iterator_traits<_It>::iterator_category; };
+      { using iterator_category = __iter_category_t<_It>; };
   } // namespace detail
 
   template<input_iterator _It>
diff --git a/libstdc++-v3/include/bits/stl_iterator_base_types.h b/libstdc++-v3/include/bits/stl_iterator_base_types.h
index 5d2c8b325d9..841b5eca3ad 100644
--- a/libstdc++-v3/include/bits/stl_iterator_base_types.h
+++ b/libstdc++-v3/include/bits/stl_iterator_base_types.h
@@ -243,16 +243,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #if __cplusplus >= 201103L
   template<typename _Iter>
-    using __iterator_category_t
+    using __iter_category_t
       = typename iterator_traits<_Iter>::iterator_category;
 
   template<typename _InIter>
     using _RequireInputIter =
-      __enable_if_t<is_convertible<__iterator_category_t<_InIter>,
+      __enable_if_t<is_convertible<__iter_category_t<_InIter>,
 				   input_iterator_tag>::value>;
 
   template<typename _It,
-	   typename _Cat = __iterator_category_t<_It>>
+	   typename _Cat = __iter_category_t<_It>>
     struct __is_random_access_iter
       : is_base_of<random_access_iterator_tag, _Cat>
     {
-- 
2.41.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [committed] libstdc++: Use alias template for iterator_category [PR110970]
  2023-08-10 22:32 [committed] libstdc++: Use alias template for iterator_category [PR110970] Jonathan Wakely
@ 2023-08-11  0:03 ` Jonathan Wakely
  2023-08-11 14:02   ` [committed] libstdc++: Revert accidentally committed change to bits/stl_iterator.h Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2023-08-11  0:03 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 5111 bytes --]

On Thu, 10 Aug 2023 at 23:34, Jonathan Wakely via Libstdc++ <
libstdc++@gcc.gnu.org> wrote:

> Tested x86_64-linux. Pushed to trunk. Backport to gcc-13 to follow.
>
> -- >8 --
>
> This renames __iterator_category_t to __iter_category_t, for consistency
> with std::iter_value_t, std::iter_difference_t and std::iter_reference_t
> in C++20. Then use __iter_category_t in <bits/stl_iterator.h>, which
> fixes the problem of the missing 'typename' that Clang 15 incorrectly
> still requires.
>
> libstdc++-v3/ChangeLog:
>
>         PR libstdc++/110970
>         * include/bits/stl_iterator.h (__detail::__move_iter_cat): Use
>         __iter_category_t.
>         (iterator_traits<common_iterator<I, S>>::_S_iter_cat): Likewise.
>         (__detail::__basic_const_iterator_iter_cat): Likewise.
>         * include/bits/stl_iterator_base_types.h (__iterator_category_t):
>         Rename to __iter_category_t.
> ---
>  libstdc++-v3/include/bits/stl_iterator.h        | 17 +++++++++--------
>  .../include/bits/stl_iterator_base_types.h      |  6 +++---
>  2 files changed, 12 insertions(+), 11 deletions(-)
>
> diff --git a/libstdc++-v3/include/bits/stl_iterator.h
> b/libstdc++-v3/include/bits/stl_iterator.h
> index b22d9a4fdb3..d5ba05f3e22 100644
> --- a/libstdc++-v3/include/bits/stl_iterator.h
> +++ b/libstdc++-v3/include/bits/stl_iterator.h
> @@ -103,6 +103,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>        using __clamp_iter_cat
>         = __conditional_t<derived_from<_Cat, _Limit>, _Limit, _Otherwise>;
>
> +    template<typename _Iter, typename _Limit>
> +      using __clamped_iter_cat_t
> +       = __clamp_iter_cat<__iter_category_t<_Iter>, _Limit>;
> +
>      template<typename _Tp, typename _Up>
>        concept __different_from
>         = !same_as<remove_cvref_t<_Tp>, remove_cvref_t<_Up>>;
> @@ -168,8 +172,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>                           random_access_iterator_tag,
>                           bidirectional_iterator_tag>;
>        using iterator_category
> -       = __detail::__clamp_iter_cat<typename
> __traits_type::iterator_category,
> -                                    random_access_iterator_tag>;
> +       = __detail::__clamped_iter_cat_t<_Iterator,
> random_access_iterator_tag>;
>        using value_type = iter_value_t<_Iterator>;
>        using difference_type = iter_difference_t<_Iterator>;
>        using reference = iter_reference_t<_Iterator>;
> @@ -1426,12 +1429,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>        { };
>
>      template<typename _Iterator>
> -      requires requires { typename
> iterator_traits<_Iterator>::iterator_category; }
> +      requires requires { typename __iter_category_t<_Iterator>; }
>        struct __move_iter_cat<_Iterator>
>        {
>         using iterator_category
> -         = __clamp_iter_cat<typename
> iterator_traits<_Iterator>::iterator_category,
> -                            random_access_iterator_tag>;
> +         = __clamped_iter_cat_t<_Iterator, random_access_iterator_tag>;
>

Oops, I only meant to commit the change to use __iter_category_t, not the
addition of __clamped_iter_cat. I'll revert that part. It was an experiment
that I decided against, and I thought I'd already reverted before
committing.




>        };
>  #endif
>    }
> @@ -2288,8 +2290,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>        static auto
>        _S_iter_cat()
>        {
> -       using _Traits = iterator_traits<_It>;
> -       if constexpr (requires { requires derived_from<typename
> _Traits::iterator_category,
> +       if constexpr (requires { requires
> derived_from<__iter_category_t<_It>,
>
>  forward_iterator_tag>; })
>           return forward_iterator_tag{};
>         else
> @@ -2615,7 +2616,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>
>      template<forward_iterator _It>
>        struct __basic_const_iterator_iter_cat<_It>
> -      { using iterator_category =
> iterator_traits<_It>::iterator_category; };
> +      { using iterator_category = __iter_category_t<_It>; };
>    } // namespace detail
>
>    template<input_iterator _It>
> diff --git a/libstdc++-v3/include/bits/stl_iterator_base_types.h
> b/libstdc++-v3/include/bits/stl_iterator_base_types.h
> index 5d2c8b325d9..841b5eca3ad 100644
> --- a/libstdc++-v3/include/bits/stl_iterator_base_types.h
> +++ b/libstdc++-v3/include/bits/stl_iterator_base_types.h
> @@ -243,16 +243,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>
>  #if __cplusplus >= 201103L
>    template<typename _Iter>
> -    using __iterator_category_t
> +    using __iter_category_t
>        = typename iterator_traits<_Iter>::iterator_category;
>
>    template<typename _InIter>
>      using _RequireInputIter =
> -      __enable_if_t<is_convertible<__iterator_category_t<_InIter>,
> +      __enable_if_t<is_convertible<__iter_category_t<_InIter>,
>                                    input_iterator_tag>::value>;
>
>    template<typename _It,
> -          typename _Cat = __iterator_category_t<_It>>
> +          typename _Cat = __iter_category_t<_It>>
>      struct __is_random_access_iter
>        : is_base_of<random_access_iterator_tag, _Cat>
>      {
> --
> 2.41.0
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [committed] libstdc++: Revert accidentally committed change to bits/stl_iterator.h
  2023-08-11  0:03 ` Jonathan Wakely
@ 2023-08-11 14:02   ` Jonathan Wakely
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2023-08-11 14:02 UTC (permalink / raw)
  To: libstdc++, gcc-patches

As promised yesterday, this reverts the part of the change I didn't mean
to commit. Tested x86_64-linux. Pushed to trunk.

-- >8 --

In commit r14-3134-g9cb2a7c8d54b1f I only meant to change some uses of
__clamp_iter_cat to use __iter_category_t, I didn't mean to commit the
additional change introducing __clamped_iter_cat_t. This reverts that
part.

libstdc++-v3/ChangeLog:

	* include/bits/stl_iterator.h (__clamped_iter_cat_t): Remove.
---
 libstdc++-v3/include/bits/stl_iterator.h | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h
index d5ba05f3e22..b13f4f8ddbf 100644
--- a/libstdc++-v3/include/bits/stl_iterator.h
+++ b/libstdc++-v3/include/bits/stl_iterator.h
@@ -103,10 +103,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       using __clamp_iter_cat
 	= __conditional_t<derived_from<_Cat, _Limit>, _Limit, _Otherwise>;
 
-    template<typename _Iter, typename _Limit>
-      using __clamped_iter_cat_t
-	= __clamp_iter_cat<__iter_category_t<_Iter>, _Limit>;
-
     template<typename _Tp, typename _Up>
       concept __different_from
 	= !same_as<remove_cvref_t<_Tp>, remove_cvref_t<_Up>>;
@@ -172,7 +168,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 			  random_access_iterator_tag,
 			  bidirectional_iterator_tag>;
       using iterator_category
-	= __detail::__clamped_iter_cat_t<_Iterator, random_access_iterator_tag>;
+	= __detail::__clamp_iter_cat<typename __traits_type::iterator_category,
+				     random_access_iterator_tag>;
       using value_type = iter_value_t<_Iterator>;
       using difference_type = iter_difference_t<_Iterator>;
       using reference = iter_reference_t<_Iterator>;
@@ -1433,7 +1430,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       struct __move_iter_cat<_Iterator>
       {
 	using iterator_category
-	  = __clamped_iter_cat_t<_Iterator, random_access_iterator_tag>;
+	  = __clamp_iter_cat<__iter_category_t<_Iterator>,
+			     random_access_iterator_tag>;
       };
 #endif
   }
-- 
2.41.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-08-11 14:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-10 22:32 [committed] libstdc++: Use alias template for iterator_category [PR110970] Jonathan Wakely
2023-08-11  0:03 ` Jonathan Wakely
2023-08-11 14:02   ` [committed] libstdc++: Revert accidentally committed change to bits/stl_iterator.h Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).