From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] libstdc++: Do not use CTAD for _Utf32_view alias template
Date: Wed, 17 Jan 2024 12:12:03 +0000 [thread overview]
Message-ID: <CACb0b4=0hnbFBMV-5chevWhX7A+9qu8uBCXWWVpgExSf8WPbHQ@mail.gmail.com> (raw)
In-Reply-To: <20240116212646.1717827-1-jwakely@redhat.com>
On Tue, 16 Jan 2024 at 21:28, Jonathan Wakely wrote:
>
> Tested aarch64-linux. I plan to push this to fix an error when using
> trunk with Clang.
Pushed.
>
> -- >8 --
>
> We were relying on P1814R0 (CTAD for alias templates) which isn't
> supported by Clang. We can just not use CTAD and provide an explicit
> template argument list for _Utf32_view.
>
> Ideally we'd define a deduction guide for _Grapheme_cluster_view that
> uses views::all_t to properly convert non-views to views, but all_t is
> defined in <ranges> and we don't want to include all of that in
> <bits/unicode.h>. So just make it require a view for now, which can be
> cheaply copied.
>
> Although it's not needed yet, it would also be more correct to
> specialize enable_borrowed_range for the views in <bits/unicode.h>.
>
> libstdc++-v3/ChangeLog:
>
> * include/bits/unicode.h (_Grapheme_cluster_view): Require view.
> Do not use CTAD for _Utf32_view.
> (__format_width, __truncate): Do not use CTAD.
> (enable_borrowed_range<_Utf_view<T, R>>): Define specialization.
> (enable_borrowed_range<_Grapheme_cluster_view<R>>): Likewise.
> ---
> libstdc++-v3/include/bits/unicode.h | 23 ++++++++++++++++++-----
> 1 file changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/libstdc++-v3/include/bits/unicode.h b/libstdc++-v3/include/bits/unicode.h
> index f1b2b359bdf..d35c83d0090 100644
> --- a/libstdc++-v3/include/bits/unicode.h
> +++ b/libstdc++-v3/include/bits/unicode.h
> @@ -714,15 +714,15 @@ inline namespace __v15_1_0
> };
>
> // Split a range into extended grapheme clusters.
> - template<ranges::forward_range _View>
> + template<ranges::forward_range _View> requires ranges::view<_View>
> class _Grapheme_cluster_view
> : public ranges::view_interface<_Grapheme_cluster_view<_View>>
> {
> public:
>
> constexpr
> - _Grapheme_cluster_view(const _View& __v)
> - : _M_begin(_Utf32_view(__v).begin())
> + _Grapheme_cluster_view(_View __v)
> + : _M_begin(_Utf32_view<_View>(std::move(__v)).begin())
> { }
>
> constexpr auto begin() const { return _M_begin; }
> @@ -946,7 +946,7 @@ inline namespace __v15_1_0
> {
> if (__s.empty()) [[unlikely]]
> return 0;
> - _Grapheme_cluster_view __gc(__s);
> + _Grapheme_cluster_view<basic_string_view<_CharT>> __gc(__s);
> auto __it = __gc.begin();
> const auto __end = __gc.end();
> size_t __n = __it.width();
> @@ -964,7 +964,7 @@ inline namespace __v15_1_0
> if (__s.empty()) [[unlikely]]
> return 0;
>
> - _Grapheme_cluster_view __gc(__s);
> + _Grapheme_cluster_view<basic_string_view<_CharT>> __gc(__s);
> auto __it = __gc.begin();
> const auto __end = __gc.end();
> size_t __n = __it.width();
> @@ -1058,6 +1058,19 @@ inline namespace __v15_1_0
>
> } // namespace __unicode
>
> +namespace ranges
> +{
> + template<typename _To, typename _Range>
> + inline constexpr bool
> + enable_borrowed_range<std::__unicode::_Utf_view<_To, _Range>>
> + = enable_borrowed_range<_Range>;
> +
> + template<typename _Range>
> + inline constexpr bool
> + enable_borrowed_range<std::__unicode::_Grapheme_cluster_view<_Range>>
> + = enable_borrowed_range<_Range>;
> +} // namespace ranges
> +
> _GLIBCXX_END_NAMESPACE_VERSION
> } // namespace std
> #endif // C++20
> --
> 2.43.0
>
prev parent reply other threads:[~2024-01-17 12:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-16 21:21 Jonathan Wakely
2024-01-17 12:12 ` 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='CACb0b4=0hnbFBMV-5chevWhX7A+9qu8uBCXWWVpgExSf8WPbHQ@mail.gmail.com' \
--to=jwakely@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).