From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id A874A3858433; Tue, 14 Mar 2023 20:46:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A874A3858433 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678826817; bh=kwuqFZgmooF7KGHkcWXBek3YqTldtjlh4DkLQROwhH8=; h=From:To:Subject:Date:From; b=FeY3eY1VkixpihKS0aBrTNjJ4VeNCbPWJt/w3rhI6WoLOiDRcNP3Bz0lvT6C+KP0V OEtzEcFiIZu+6UsPfq9ESoGFsxWTGX3gUPo+u5GGiKoH9/IItijDX/+hBsQR2goGGr DPYKdSEogRYiA6+QRSIa4fiLDCnOS1xpNJ5zsC7s= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-6673] libstdc++: Implement P2520R0 changes to move_iterator's iterator_concept X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: f2e7dd8b023b8de30af608afd68e0ecefa5c1de6 X-Git-Newrev: 2b204accd07a3185b58b1edc6e9b019472857a5d Message-Id: <20230314204657.A874A3858433@sourceware.org> Date: Tue, 14 Mar 2023 20:46:57 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2b204accd07a3185b58b1edc6e9b019472857a5d commit r13-6673-g2b204accd07a3185b58b1edc6e9b019472857a5d Author: Patrick Palka Date: Tue Mar 14 16:44:32 2023 -0400 libstdc++: Implement P2520R0 changes to move_iterator's iterator_concept 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. Diff: --- 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(-) 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; #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 +#if __cpp_lib_move_iterator_concept != 202207L +# error "Feature-test macro __cpp_lib_move_iterator_concept has wrong value in " +#endif + +#undef __cpp_lib_move_iterator_concept +#include +#if __cpp_lib_move_iterator_concept != 202207L +# error "Feature-test macro __cpp_lib_move_iterator_concept has wrong value in " +#endif + +#include + +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&>().begin())>; +static_assert(std::same_as); + +using ty2 = std::move_iterator&>().begin())>; +static_assert(std::same_as); + +using ty3 = std::move_iterator&>().begin())>; +static_assert(std::same_as); + +using ty4 = std::move_iterator&>().begin())>; +static_assert(std::same_as); + +static_assert(std::random_access_iterator>);