@@ -1048,7 +1048,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// [optional.monadic]
- template<typename _Fn> requires invocable<_Fn, _Tp&>
+ template<typename _Fn>
constexpr auto
and_then(_Fn&& __f) &
{
@@ -1060,7 +1060,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return _Up();
}
- template<typename _Fn> requires invocable<_Fn, const _Tp&>
+ template<typename _Fn>
constexpr auto
and_then(_Fn&& __f) const &
{
@@ -1072,7 +1072,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return _Up();
}
- template<typename _Fn> requires invocable<_Fn, _Tp>
+ template<typename _Fn>
constexpr auto
and_then(_Fn&& __f) &&
{
@@ -1084,7 +1084,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return _Up();
}
- template<typename _Fn> requires invocable<_Fn, const _Tp>
+ template<typename _Fn>
constexpr auto
and_then(_Fn&& __f) const &&
{
@@ -1096,7 +1096,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return _Up();
}
- template<typename _Fn> requires invocable<_Fn, _Tp&>
+ template<typename _Fn>
constexpr auto
transform(_Fn&& __f) &
{
@@ -1107,7 +1107,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return optional<_Up>();
}
- template<typename _Fn> requires invocable<_Fn, const _Tp&>
+ template<typename _Fn>
constexpr auto
transform(_Fn&& __f) const &
{
@@ -1118,7 +1118,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return optional<_Up>();
}
- template<typename _Fn> requires invocable<_Fn, _Tp>
+ template<typename _Fn>
constexpr auto
transform(_Fn&& __f) &&
{
@@ -1129,7 +1129,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return optional<_Up>();
}
- template<typename _Fn> requires invocable<_Fn, const _Tp>
+ template<typename _Fn>
constexpr auto
transform(_Fn&& __f) const &&
{
@@ -113,8 +113,20 @@ test_forwarding()
static_assert( test_forwarding() );
+void f(int&) { }
+
+void
+test_unconstrained()
+{
+ // PR libstc++/102863 - Optional monadic ops should not be constrained
+ std::optional<int> x;
+ auto answer = x.and_then([](auto& y) { f(y); return std::optional<int>{42}; });
+ VERIFY( !answer );
+}
+
int main()
{
test_and_then();
test_forwarding();
+ test_unconstrained();
}
@@ -132,9 +132,21 @@ test_copy_elision()
static_assert( test_copy_elision() );
+void f(int&) { }
+
+void
+test_unconstrained()
+{
+ // PR libstc++/102863 - Optional monadic ops should not be constrained
+ std::optional<int> x;
+ auto answer = x.transform([](auto& y) { f(y); return 42; });
+ VERIFY( !answer );
+}
+
int main()
{
test_transform();
test_forwarding();
test_copy_elision();
+ test_unconstrained();
}