public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Patrick Palka <ppalka@redhat.com>
Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: [PATCH] libstdc++: Implement P2520R0 changes to move_iterator's iterator_concept
Date: Thu, 9 Mar 2023 17:55:55 +0000	[thread overview]
Message-ID: <CACb0b4nYLWY37jdYU6CiNWDWmhHYrStSreUphxQg+SatGQTY1Q@mail.gmail.com> (raw)
In-Reply-To: <20230308164651.325398-1-ppalka@redhat.com>

On Wed, 8 Mar 2023 at 16:47, Patrick Palka via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk and perhaps
> backports?

Yes for all.


>
> libstdc++-v3/ChangeLog:
>
>         * include/bits/stl_iterator.h (move_iterator::_S_iter_concept):
>         Define.
>         (__cpp_lib_move_iterator_concept): Define for C++20.
>         (move_iterator::iterator_concept): Strengthen as per P2520R0.
>         * include/std/version (__cpp_lib_move_iterator_concept): Define
>         for C++20.
>         * testsuite/24_iterators/move_iterator/p2520r0.cc: New test.
> ---
>  libstdc++-v3/include/bits/stl_iterator.h      | 20 +++++++++-
>  libstdc++-v3/include/std/version              |  1 +
>  .../24_iterators/move_iterator/p2520r0.cc     | 37 +++++++++++++++++++
>  3 files changed, 57 insertions(+), 1 deletion(-)
>  create mode 100644 libstdc++-v3/testsuite/24_iterators/move_iterator/p2520r0.cc
>
> diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h
> index c20dc9ecac5..a6a09dbac16 100644
> --- a/libstdc++-v3/include/bits/stl_iterator.h
> +++ b/libstdc++-v3/include/bits/stl_iterator.h
> @@ -1465,11 +1465,29 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>             && convertible_to<const _Iter2&, _Iterator>;
>  #endif
>
> +#if __cplusplus > 201703L && __cpp_lib_concepts
> +      static auto
> +      _S_iter_concept()
> +      {
> +       if constexpr (random_access_iterator<_Iterator>)
> +         return random_access_iterator_tag{};
> +       else if constexpr (bidirectional_iterator<_Iterator>)
> +         return bidirectional_iterator_tag{};
> +       else if constexpr (forward_iterator<_Iterator>)
> +         return forward_iterator_tag{};
> +       else
> +         return input_iterator_tag{};
> +      }
> +#endif
> +
>      public:
>        using iterator_type = _Iterator;
>
>  #if __cplusplus > 201703L && __cpp_lib_concepts
> -      using iterator_concept = input_iterator_tag;
> +      // This is P2520R0, a C++23 change, but we treat it as a DR against C++20.
> +# define __cpp_lib_move_iterator_concept 202207L
> +      using iterator_concept = decltype(_S_iter_concept());
> +
>        // iterator_category defined in __move_iter_cat
>        using value_type = iter_value_t<_Iterator>;
>        using difference_type = iter_difference_t<_Iterator>;
> diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version
> index 871d30db5b3..25ebfc3e512 100644
> --- a/libstdc++-v3/include/std/version
> +++ b/libstdc++-v3/include/std/version
> @@ -289,6 +289,7 @@
>  #define __cpp_lib_polymorphic_allocator 201902L
>  #if __cpp_lib_concepts
>  # define __cpp_lib_ranges 202110L
> +# define __cpp_lib_move_iterator_concept 202207L
>  #endif
>  #if __cpp_lib_atomic_wait || _GLIBCXX_HAVE_POSIX_SEMAPHORE
>  # define __cpp_lib_semaphore 201907L
> diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/p2520r0.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/p2520r0.cc
> new file mode 100644
> index 00000000000..883d6cc09e0
> --- /dev/null
> +++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/p2520r0.cc
> @@ -0,0 +1,37 @@
> +// { dg-options "-std=gnu++20" }
> +// { dg-do compile { target c++20 } }
> +
> +// Verify P2520R0 changes to move_iterator's iterator_concept, which we treat
> +// as a DR against C++20.
> +
> +#include <iterator>
> +#if __cpp_lib_move_iterator_concept != 202207L
> +# error "Feature-test macro __cpp_lib_move_iterator_concept has wrong value in <iterator>"
> +#endif
> +
> +#undef __cpp_lib_move_iterator_concept
> +#include <version>
> +#if __cpp_lib_move_iterator_concept != 202207L
> +# error "Feature-test macro __cpp_lib_move_iterator_concept has wrong value in <version>"
> +#endif
> +
> +#include <testsuite_iterators.h>
> +
> +using __gnu_test::test_input_range;
> +using __gnu_test::test_forward_range;
> +using __gnu_test::test_bidirectional_range;
> +using __gnu_test::test_random_access_range;
> +
> +using ty1 = std::move_iterator<decltype(std::declval<test_input_range<int>&>().begin())>;
> +static_assert(std::same_as<ty1::iterator_concept, std::input_iterator_tag>);
> +
> +using ty2 = std::move_iterator<decltype(std::declval<test_forward_range<int>&>().begin())>;
> +static_assert(std::same_as<ty2::iterator_concept, std::forward_iterator_tag>);
> +
> +using ty3 = std::move_iterator<decltype(std::declval<test_bidirectional_range<int>&>().begin())>;
> +static_assert(std::same_as<ty3::iterator_concept, std::bidirectional_iterator_tag>);
> +
> +using ty4 = std::move_iterator<decltype(std::declval<test_random_access_range<int>&>().begin())>;
> +static_assert(std::same_as<ty4::iterator_concept, std::random_access_iterator_tag>);
> +
> +static_assert(std::random_access_iterator<std::move_iterator<int*>>);
> --
> 2.40.0.rc0.57.g454dfcbddf
>


      reply	other threads:[~2023-03-09 17:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08 16:46 Patrick Palka
2023-03-09 17:55 ` Jonathan Wakely [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACb0b4nYLWY37jdYU6CiNWDWmhHYrStSreUphxQg+SatGQTY1Q@mail.gmail.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --cc=ppalka@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).