From: Patrick Palka <ppalka@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: libstdc++@gcc.gnu.org, Patrick Palka <ppalka@redhat.com>
Subject: [PATCH 1/2] libstdc++: Move down definitions of ranges::cbegin/cend/cetc
Date: Fri, 14 Apr 2023 00:00:41 -0400 [thread overview]
Message-ID: <20230414040042.1498825-1-ppalka@redhat.com> (raw)
This moves down the definitions of the const range access CPOs to after
the definition of input_range in preparation for implementing P2287R4
which redefines these CPOs in a way that indirectly uses input_range.
tested on x86_64-pc-linux-gnu, does this look OK for trunk?
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.
---
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<typename _To, typename _Tp>
- 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<const _Tp&>(__t);
- else
- return static_cast<const _Tp&&>(__t);
- }
-
- struct _CBegin
- {
- template<typename _Tp>
- [[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<typename _Tp>
- [[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<typename _Tp>
concept __member_rbegin = requires(_Tp& __t)
{
@@ -337,32 +298,6 @@ namespace ranges
}
};
- struct _CRBegin
- {
- template<typename _Tp>
- [[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<typename _Tp>
- [[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<typename _Tp>
concept __member_size = !disable_sized_range<remove_cvref_t<_Tp>>
&& requires(_Tp& __t)
@@ -547,36 +482,18 @@ namespace ranges
}
};
- struct _CData
- {
- template<typename _Tp>
- [[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<iterator_t<_Tp>, sentinel_t<_Tp>>;
+ namespace __cust_access
+ {
+ // If _To is an lvalue-reference, return const _Tp&, otherwise const _Tp&&.
+ template<typename _To, typename _Tp>
+ 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<const _Tp&>(__t);
+ else
+ return static_cast<const _Tp&&>(__t);
+ }
+
+ struct _CBegin
+ {
+ template<typename _Tp>
+ [[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<typename _Tp>
+ [[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<typename _Tp>
+ [[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<typename _Tp>
+ [[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<typename _Tp>
+ [[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<typename _Tp>
--
2.40.0.335.g9857273be0
next reply other threads:[~2023-04-14 4:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-14 4:00 Patrick Palka [this message]
2023-04-14 4:00 ` [PATCH 2/2] libstdc++: Implement P2278R4 "cbegin should always return a constant iterator" Patrick Palka
2023-04-14 9:52 ` Ville Voutilainen
2023-04-14 10:14 ` Jonathan Wakely
2023-04-14 14:14 ` Patrick Palka
2023-04-14 9:49 ` [PATCH 1/2] libstdc++: Move down definitions of ranges::cbegin/cend/cetc Jonathan Wakely
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=20230414040042.1498825-1-ppalka@redhat.com \
--to=ppalka@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/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).