From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 9CB713857C69; Tue, 6 Oct 2020 13:09:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9CB713857C69 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-8860] libstdc++: Add missing P0896 changes to X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 1ab88985631dd2c5a5e3b5c0dce47cf8b6ed2f82 X-Git-Newrev: 36e6194e4bfc02f18a48e8c4ba141f7541c0debb Message-Id: <20201006130935.9CB713857C69@sourceware.org> Date: Tue, 6 Oct 2020 13:09:35 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Oct 2020 13:09:35 -0000 https://gcc.gnu.org/g:36e6194e4bfc02f18a48e8c4ba141f7541c0debb commit r10-8860-g36e6194e4bfc02f18a48e8c4ba141f7541c0debb Author: Patrick Palka Date: Fri Oct 2 10:51:31 2020 -0400 libstdc++: Add missing P0896 changes to I noticed that the following changes from this paper were not yet implemented. libstdc++-v3/ChangeLog: * include/bits/stl_iterator.h (reverse_iterator::iter_move): Define for C++20 as per P0896. (reverse_iterator::iter_swap): Likewise. (move_iterator::operator*): Apply P0896 changes for C++20. (move_iterator::operator[]): Likewise. * testsuite/24_iterators/reverse_iterator/cust.cc: New test. (cherry picked from commit 080a23bce12fa3f25860631f019777f728d2ef11) Diff: --- libstdc++-v3/include/bits/stl_iterator.h | 33 ++++++++++++++ .../24_iterators/reverse_iterator/cust.cc | 52 ++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index d6bb085b3c6..8f3d54852a1 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -332,6 +332,31 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION operator[](difference_type __n) const { return *(*this + __n); } +#if __cplusplus > 201703L && __cpp_lib_concepts + friend constexpr iter_rvalue_reference_t<_Iterator> + iter_move(const reverse_iterator& __i) + noexcept(is_nothrow_copy_constructible_v<_Iterator> + && noexcept(ranges::iter_move(--std::declval<_Iterator&>()))) + { + auto __tmp = __i.base(); + return ranges::iter_move(--__tmp); + } + + template _Iter2> + friend constexpr void + iter_swap(const reverse_iterator& __x, + const reverse_iterator<_Iter2>& __y) + noexcept(is_nothrow_copy_constructible_v<_Iterator> + && is_nothrow_copy_constructible_v<_Iter2> + && noexcept(ranges::iter_swap(--std::declval<_Iterator&>(), + --std::declval<_Iter2&>()))) + { + auto __xtmp = __x.base(); + auto __ytmp = __y.base(); + ranges::iter_swap(--__xtmp, --__ytmp); + } +#endif + private: template static _GLIBCXX17_CONSTEXPR _Tp* @@ -1325,7 +1350,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX17_CONSTEXPR reference operator*() const +#if __cplusplus > 201703L && __cpp_lib_concepts + { return ranges::iter_move(_M_current); } +#else { return static_cast(*_M_current); } +#endif _GLIBCXX17_CONSTEXPR pointer operator->() const @@ -1391,7 +1420,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX17_CONSTEXPR reference operator[](difference_type __n) const +#if __cplusplus > 201703L && __cpp_lib_concepts + { return ranges::iter_move(_M_current + __n); } +#else { return std::move(_M_current[__n]); } +#endif #if __cplusplus > 201703L && __cpp_lib_concepts template _Sent> diff --git a/libstdc++-v3/testsuite/24_iterators/reverse_iterator/cust.cc b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/cust.cc new file mode 100644 index 00000000000..ac86312fbe7 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/reverse_iterator/cust.cc @@ -0,0 +1,52 @@ +// Copyright (C) 2019-2020 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++2a" } +// { dg-do compile { target c++2a } } + +#include +#include + +// This test is an adaptation of 24_iterators/move_iterator/cust.cc. + +constexpr bool +test01() +{ + struct X + { + constexpr X(int i) noexcept : i(i) { } + constexpr X(X&& x) noexcept : i(x.i) { x.i = -1; } + constexpr X& operator=(X&& x) noexcept { i = x.i; x.i = 0; return *this; } + int i; + }; + + X arr[] = { 1, 2 }; + std::reverse_iterator i(arr + 1), j(arr + 2); + static_assert(noexcept(std::ranges::iter_swap(i, j))); + std::ranges::iter_swap(i, j); + VERIFY( arr[0].i == 2 ); + VERIFY( arr[1].i == 1 ); + + static_assert(noexcept(std::ranges::iter_move(i))); + X x = std::ranges::iter_move(i); + VERIFY( arr[0].i == -1 ); + VERIFY( x.i == 2 ); + + return true; +} + +static_assert(test01());