From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Fix std::ranges::to errors
Date: Thu, 30 Nov 2023 15:47:24 +0000 [thread overview]
Message-ID: <20231130154744.74164-1-jwakely@redhat.com> (raw)
Tested x86_64-linux. Pushed to trunk.
-- >8 --
Fix some errors that Patrick noticed, and remove a #if 0 group that I
didn't mean to leave in the file.
libstdc++-v3/ChangeLog:
* include/std/ranges (__detail::__toable): Fix incorrect use of
_Range instead of _Cont.
(__detail::_ToClosure, __detail::_ToClosure2): Add missing
constexpr specifier on constructors.
* testsuite/std/ranges/conv/1.cc (_Cont, _Cont2, _Cont3): Remove
unnecessary begin() and end() members.
(test_constexpr): New function to check range adaptors are
usable in constant expressions.
---
libstdc++-v3/include/std/ranges | 26 +++---------------
libstdc++-v3/testsuite/std/ranges/conv/1.cc | 29 +++++++++++----------
2 files changed, 19 insertions(+), 36 deletions(-)
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index 63bea862c05..9d4c2e01c4d 100644
--- a/libstdc++-v3/include/std/ranges
+++ b/libstdc++-v3/include/std/ranges
@@ -9251,7 +9251,7 @@ namespace __detail
template<typename _Cont, typename _Range>
constexpr bool __toable = requires {
- requires (!input_range<_Range>
+ requires (!input_range<_Cont>
|| convertible_to<range_reference_t<_Range>,
range_value_t<_Cont>>);
};
@@ -9290,7 +9290,7 @@ namespace __detail
else if constexpr (constructible_from<_Cont, from_range_t, _Rg, _Args...>)
return _Cont(from_range, std::forward<_Rg>(__r),
std::forward<_Args>(__args)...);
- else if constexpr (requires { common_range<_Rg>;
+ else if constexpr (requires { requires common_range<_Rg>;
typename __iter_category_t<iterator_t<_Rg>>;
requires derived_from<__iter_category_t<iterator_t<_Rg>>,
input_iterator_tag>;
@@ -9346,26 +9346,6 @@ namespace __detail
bool operator==(const _InputIter&) const;
};
-#if 0
- template<template<typename...> typename _Cont, typename _Rg,
- typename... _Args>
- concept __deduce_expr_1 = requires {
- _Cont(std::declval<_Rg>(), std::declval<_Args>()...);
- };
-
- template<template<typename...> typename _Cont, typename _Rg,
- typename... _Args>
- concept __deduce_expr_2 = requires {
- _Cont(from_range, std::declval<_Rg>(), std::declval<_Args>()...);
- };
-
- template<template<typename...> typename _Cont, typename _Rg,
- typename... _Args>
- concept __deduce_expr_3 = requires(_InputIter<_Rg> __i) {
- _Cont(std::move(__i), std::move(__i), std::declval<_Args>()...);
- };
-#endif
-
template<template<typename...> typename _Cont, input_range _Rg,
typename... _Args>
using _DeduceExpr1
@@ -9418,6 +9398,7 @@ namespace __detail
tuple<decay_t<_Args>...> _M_bound_args;
public:
+ constexpr
_ToClosure(_Args&&... __args)
: _M_bound_args(std::forward<_Args>(__args)...)
{ }
@@ -9498,6 +9479,7 @@ namespace __detail
tuple<decay_t<_Args>...> _M_bound_args;
public:
+ constexpr
_ToClosure2(_Args&&... __args)
: _M_bound_args(std::forward<_Args>(__args)...)
{ }
diff --git a/libstdc++-v3/testsuite/std/ranges/conv/1.cc b/libstdc++-v3/testsuite/std/ranges/conv/1.cc
index 0032cf32688..4b6814b1add 100644
--- a/libstdc++-v3/testsuite/std/ranges/conv/1.cc
+++ b/libstdc++-v3/testsuite/std/ranges/conv/1.cc
@@ -89,9 +89,6 @@ struct Cont1
: c(r, args...)
{ }
- typename C::iterator begin();
- typename C::iterator end();
-
C c;
};
@@ -153,9 +150,6 @@ struct Cont2
: c(r, args...)
{ }
- typename C::iterator begin();
- typename C::iterator end();
-
C c;
};
@@ -186,9 +180,6 @@ struct Cont3
: c(first, last, args...)
{ }
- typename C::iterator begin();
- typename C::iterator end();
-
C c;
};
@@ -222,10 +213,6 @@ struct Cont4
Cont4() { }
Cont4(typename C::allocator_type a) : c(a) { }
- // Required to satisfy range
- typename C::iterator begin() { return c.begin(); }
- typename C::iterator end() { return c.end(); }
-
// Satisfying container-insertable requires either this ...
template<typename T>
requires UsePushBack
@@ -254,7 +241,9 @@ struct Cont4
used_reserve = true;
}
- // Required to satisfy reservable-container
+ // Satisfying sized_range is required to satisfy reservable-container
+ typename C::iterator begin() { return c.begin(); }
+ typename C::iterator end() { return c.end(); }
auto size() const { return c.size(); }
// Required to satisfy reservable-container
@@ -355,6 +344,17 @@ test_nodiscard()
std::ranges::to<std::vector>(); // { dg-warning "ignoring return" }
}
+void
+test_constexpr()
+{
+ constexpr int x = [](int i) {
+ auto c1 = std::views::iota(1, i) | std::ranges::to<std::vector<int>>();
+ auto c2 = std::views::iota(i, 10) | std::ranges::to<std::vector>();
+ return c1[0] + c2[0];
+ }(5);
+ static_assert(x == 6);
+}
+
int main()
{
test_p1206r7_examples();
@@ -366,4 +366,5 @@ int main()
test_2_2();
test_lwg3984();
test_nodiscard();
+ test_constexpr();
}
--
2.43.0
reply other threads:[~2023-11-30 15:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20231130154744.74164-1-jwakely@redhat.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).