From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 7A4DE3858C60; Fri, 14 Apr 2023 14:32:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A4DE3858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681482759; bh=yoy947nUYfgBczuBOZGQ82pjFTBm0mKSb3cQpgRV5l4=; h=From:To:Subject:Date:From; b=rK7TeG7tLqno18FKkIzHt1ifM7VnkTZfOXgxzuI9wMGJoLrzcz0zb8cBO9WzHf92a CXNKMkZ/onmvnh39mIb0xmad5zAbM7jB5qkEbRQUHAJdZKxkxUAHgNBsQqz9ouQmjo ls5tHzIj7hQyqW5WBIda3YPKOG4dkV3JEjz2dSz4= 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-7185] libstdc++: Move down definitions of ranges::cbegin/cend/cetc X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: 7639bf34fa1942b0a56a0ba441637c1ce75e1127 X-Git-Newrev: 2ab0d83e8880fe747af3f137aef382d2d4c09e4c Message-Id: <20230414143239.7A4DE3858C60@sourceware.org> Date: Fri, 14 Apr 2023 14:32:39 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2ab0d83e8880fe747af3f137aef382d2d4c09e4c commit r13-7185-g2ab0d83e8880fe747af3f137aef382d2d4c09e4c Author: Patrick Palka Date: Fri Apr 14 10:31:54 2023 -0400 libstdc++: Move down definitions of ranges::cbegin/cend/cetc This moves down the definitions of the range const-access CPOs to after the definition of input_range in preparation for implementing P2278R4 which redefines these CPOs in a way that indirectly uses input_range. libstdc++-v3/ChangeLog: * include/bits/ranges_base.h (__cust_access::__as_const) (__cust_access::_CBegin, __cust::cbegin) (__cust_access::_CEnd, __cust::cend) (__cust_access::_CRBegin, __cust::crbegin) (__cust_access::_CREnd, __cust::crend) (__cust_access::_CData, __cust::cdata): Move down definitions to shortly after the definition of input_range. Diff: --- libstdc++-v3/include/bits/ranges_base.h | 174 +++++++++++++++++--------------- 1 file changed, 91 insertions(+), 83 deletions(-) diff --git a/libstdc++-v3/include/bits/ranges_base.h b/libstdc++-v3/include/bits/ranges_base.h index 86952b34096..c89cb3e976a 100644 --- a/libstdc++-v3/include/bits/ranges_base.h +++ b/libstdc++-v3/include/bits/ranges_base.h @@ -177,45 +177,6 @@ namespace ranges } }; - // If _To is an lvalue-reference, return const _Tp&, otherwise const _Tp&&. - template - constexpr decltype(auto) - __as_const(_Tp& __t) noexcept - { - static_assert(std::is_same_v<_To&, _Tp&>); - - if constexpr (is_lvalue_reference_v<_To>) - return const_cast(__t); - else - return static_cast(__t); - } - - struct _CBegin - { - template - [[nodiscard]] - constexpr auto - operator()(_Tp&& __e) const - noexcept(noexcept(_Begin{}(__cust_access::__as_const<_Tp>(__e)))) - requires requires { _Begin{}(__cust_access::__as_const<_Tp>(__e)); } - { - return _Begin{}(__cust_access::__as_const<_Tp>(__e)); - } - }; - - struct _CEnd final - { - template - [[nodiscard]] - constexpr auto - operator()(_Tp&& __e) const - noexcept(noexcept(_End{}(__cust_access::__as_const<_Tp>(__e)))) - requires requires { _End{}(__cust_access::__as_const<_Tp>(__e)); } - { - return _End{}(__cust_access::__as_const<_Tp>(__e)); - } - }; - template concept __member_rbegin = requires(_Tp& __t) { @@ -337,32 +298,6 @@ namespace ranges } }; - struct _CRBegin - { - template - [[nodiscard]] - constexpr auto - operator()(_Tp&& __e) const - noexcept(noexcept(_RBegin{}(__cust_access::__as_const<_Tp>(__e)))) - requires requires { _RBegin{}(__cust_access::__as_const<_Tp>(__e)); } - { - return _RBegin{}(__cust_access::__as_const<_Tp>(__e)); - } - }; - - struct _CREnd - { - template - [[nodiscard]] - constexpr auto - operator()(_Tp&& __e) const - noexcept(noexcept(_REnd{}(__cust_access::__as_const<_Tp>(__e)))) - requires requires { _REnd{}(__cust_access::__as_const<_Tp>(__e)); } - { - return _REnd{}(__cust_access::__as_const<_Tp>(__e)); - } - }; - template concept __member_size = !disable_sized_range> && requires(_Tp& __t) @@ -547,36 +482,18 @@ namespace ranges } }; - struct _CData - { - template - [[nodiscard]] - constexpr auto - operator()(_Tp&& __e) const - noexcept(noexcept(_Data{}(__cust_access::__as_const<_Tp>(__e)))) - requires requires { _Data{}(__cust_access::__as_const<_Tp>(__e)); } - { - return _Data{}(__cust_access::__as_const<_Tp>(__e)); - } - }; - } // namespace __cust_access inline namespace __cust { inline constexpr __cust_access::_Begin begin{}; inline constexpr __cust_access::_End end{}; - inline constexpr __cust_access::_CBegin cbegin{}; - inline constexpr __cust_access::_CEnd cend{}; inline constexpr __cust_access::_RBegin rbegin{}; inline constexpr __cust_access::_REnd rend{}; - inline constexpr __cust_access::_CRBegin crbegin{}; - inline constexpr __cust_access::_CREnd crend{}; inline constexpr __cust_access::_Size size{}; inline constexpr __cust_access::_SSize ssize{}; inline constexpr __cust_access::_Empty empty{}; inline constexpr __cust_access::_Data data{}; - inline constexpr __cust_access::_CData cdata{}; } /// [range.range] The range concept. @@ -690,6 +607,97 @@ namespace ranges concept common_range = range<_Tp> && same_as, sentinel_t<_Tp>>; + namespace __cust_access + { + // If _To is an lvalue-reference, return const _Tp&, otherwise const _Tp&&. + template + constexpr decltype(auto) + __as_const(_Tp& __t) noexcept + { + static_assert(std::is_same_v<_To&, _Tp&>); + + if constexpr (is_lvalue_reference_v<_To>) + return const_cast(__t); + else + return static_cast(__t); + } + + struct _CBegin + { + template + [[nodiscard]] + constexpr auto + operator()(_Tp&& __e) const + noexcept(noexcept(_Begin{}(__cust_access::__as_const<_Tp>(__e)))) + requires requires { _Begin{}(__cust_access::__as_const<_Tp>(__e)); } + { + return _Begin{}(__cust_access::__as_const<_Tp>(__e)); + } + }; + + struct _CEnd final + { + template + [[nodiscard]] + constexpr auto + operator()(_Tp&& __e) const + noexcept(noexcept(_End{}(__cust_access::__as_const<_Tp>(__e)))) + requires requires { _End{}(__cust_access::__as_const<_Tp>(__e)); } + { + return _End{}(__cust_access::__as_const<_Tp>(__e)); + } + }; + + struct _CRBegin + { + template + [[nodiscard]] + constexpr auto + operator()(_Tp&& __e) const + noexcept(noexcept(_RBegin{}(__cust_access::__as_const<_Tp>(__e)))) + requires requires { _RBegin{}(__cust_access::__as_const<_Tp>(__e)); } + { + return _RBegin{}(__cust_access::__as_const<_Tp>(__e)); + } + }; + + struct _CREnd + { + template + [[nodiscard]] + constexpr auto + operator()(_Tp&& __e) const + noexcept(noexcept(_REnd{}(__cust_access::__as_const<_Tp>(__e)))) + requires requires { _REnd{}(__cust_access::__as_const<_Tp>(__e)); } + { + return _REnd{}(__cust_access::__as_const<_Tp>(__e)); + } + }; + + struct _CData + { + template + [[nodiscard]] + constexpr auto + operator()(_Tp&& __e) const + noexcept(noexcept(_Data{}(__cust_access::__as_const<_Tp>(__e)))) + requires requires { _Data{}(__cust_access::__as_const<_Tp>(__e)); } + { + return _Data{}(__cust_access::__as_const<_Tp>(__e)); + } + }; + + } // namespace __cust_access + + inline namespace __cust + { + inline constexpr __cust_access::_CBegin cbegin{}; + inline constexpr __cust_access::_CEnd cend{}; + inline constexpr __cust_access::_CRBegin crbegin{}; + inline constexpr __cust_access::_CREnd crend{}; + inline constexpr __cust_access::_CData cdata{}; + } + namespace __detail { template