template<typename _Fn, typename _Tp>
using __result = remove_cvref_t<invoke_result_t<_Fn&&, _Tp&&>>;
+ template<typename _Fn, typename _Tp>
+ using __result_xform = remove_cv_t<invoke_result_t<_Fn&&, _Tp&&>>;
template<typename _Fn>
using __result0 = remove_cvref_t<invoke_result_t<_Fn&&>>;
+ template<typename _Fn>
+ using __result0_xform = remove_cv_t<invoke_result_t<_Fn&&>>;
template<typename _Er>
concept __can_be_unexpected
constexpr auto
transform(_Fn&& __f) &
{
- using _Up = __expected::__result<_Fn, _Tp&>;
+ using _Up = __expected::__result_xform<_Fn, _Tp&>;
using _Res = expected<_Up, _Er>;
if (has_value())
constexpr auto
transform(_Fn&& __f) const &
{
- using _Up = __expected::__result<_Fn, const _Tp&>;
+ using _Up = __expected::__result_xform<_Fn, const _Tp&>;
using _Res = expected<_Up, _Er>;
if (has_value())
constexpr auto
transform(_Fn&& __f) &&
{
- using _Up = __expected::__result<_Fn, _Tp>;
+ using _Up = __expected::__result_xform<_Fn, _Tp>;
using _Res = expected<_Up, _Er>;
if (has_value())
constexpr auto
transform(_Fn&& __f) const &&
{
- using _Up = __expected::__result<_Fn, const _Tp>;
+ using _Up = __expected::__result_xform<_Fn, const _Tp>;
using _Res = expected<_Up, _Er>;
if (has_value())
constexpr auto
transform_error(_Fn&& __f) &
{
- using _Gr = __expected::__result<_Fn, _Er&>;
+ using _Gr = __expected::__result_xform<_Fn, _Er&>;
using _Res = expected<_Tp, _Gr>;
if (has_value())
constexpr auto
transform_error(_Fn&& __f) const &
{
- using _Gr = __expected::__result<_Fn, const _Er&>;
+ using _Gr = __expected::__result_xform<_Fn, const _Er&>;
using _Res = expected<_Tp, _Gr>;
if (has_value())
constexpr auto
transform_error(_Fn&& __f) &&
{
- using _Gr = __expected::__result<_Fn, _Er&&>;
+ using _Gr = __expected::__result_xform<_Fn, _Er&&>;
using _Res = expected<_Tp, _Gr>;
if (has_value())
constexpr auto
transform_error(_Fn&& __f) const &&
{
- using _Gr = __expected::__result<_Fn, const _Er&&>;
+ using _Gr = __expected::__result_xform<_Fn, const _Er&&>;
using _Res = expected<_Tp, _Gr>;
if (has_value())
constexpr auto
transform(_Fn&& __f) &
{
- using _Up = __expected::__result0<_Fn>;
+ using _Up = __expected::__result0_xform<_Fn>;
using _Res = expected<_Up, _Er>;
if (has_value())
constexpr auto
transform(_Fn&& __f) const &
{
- using _Up = __expected::__result0<_Fn>;
+ using _Up = __expected::__result0_xform<_Fn>;
using _Res = expected<_Up, _Er>;
if (has_value())
constexpr auto
transform(_Fn&& __f) &&
{
- using _Up = __expected::__result0<_Fn>;
+ using _Up = __expected::__result0_xform<_Fn>;
using _Res = expected<_Up, _Er>;
if (has_value())
constexpr auto
transform(_Fn&& __f) const &&
{
- using _Up = __expected::__result0<_Fn>;
+ using _Up = __expected::__result0_xform<_Fn>;
using _Res = expected<_Up, _Er>;
if (has_value())
constexpr auto
transform_error(_Fn&& __f) &
{
- using _Gr = __expected::__result<_Fn, _Er&>;
+ using _Gr = __expected::__result_xform<_Fn, _Er&>;
using _Res = expected<_Tp, _Gr>;
if (has_value())
constexpr auto
transform_error(_Fn&& __f) const &
{
- using _Gr = __expected::__result<_Fn, const _Er&>;
+ using _Gr = __expected::__result_xform<_Fn, const _Er&>;
using _Res = expected<_Tp, _Gr>;
if (has_value())
constexpr auto
transform_error(_Fn&& __f) &&
{
- using _Gr = __expected::__result<_Fn, _Er&&>;
+ using _Gr = __expected::__result_xform<_Fn, _Er&&>;
using _Res = expected<_Tp, _Gr>;
if (has_value())
constexpr auto
transform_error(_Fn&& __f) const &&
{
- using _Gr = __expected::__result<_Fn, const _Er&&>;
+ using _Gr = __expected::__result_xform<_Fn, const _Er&&>;
using _Res = expected<_Tp, _Gr>;
if (has_value())
constexpr auto
transform(_Fn&& __f) &
{
- using _Up = invoke_result_t<_Fn, _Tp&>;
+ using _Up = remove_cv_t<invoke_result_t<_Fn, _Tp&>>;
if (has_value())
return optional<_Up>(_Optional_func<_Fn>{__f}, **this);
else
constexpr auto
transform(_Fn&& __f) const &
{
- using _Up = invoke_result_t<_Fn, const _Tp&>;
+ using _Up = remove_cv_t<invoke_result_t<_Fn, const _Tp&>>;
if (has_value())
return optional<_Up>(_Optional_func<_Fn>{__f}, **this);
else
constexpr auto
transform(_Fn&& __f) &&
{
- using _Up = invoke_result_t<_Fn, _Tp>;
+ using _Up = remove_cv_t<invoke_result_t<_Fn, _Tp>>;
if (has_value())
return optional<_Up>(_Optional_func<_Fn>{__f}, std::move(**this));
else
constexpr auto
transform(_Fn&& __f) const &&
{
- using _Up = invoke_result_t<_Fn, const _Tp>;
+ using _Up = remove_cv_t<invoke_result_t<_Fn, const _Tp>>;
if (has_value())
return optional<_Up>(_Optional_func<_Fn>{__f}, std::move(**this));
else
--- /dev/null
+// { dg-options "-std=gnu++23" }
+// { dg-do compile { target c++23 } }
+
+#include <optional>
+
+// PR libstdc++/109242
+// transform omits required std::remove_cv_t from return optional type
+
+struct A { };
+struct B { };
+struct C { };
+struct D { };
+
+struct F
+{
+ const A operator()(int&);
+ const B operator()(const int&);
+ const C operator()(int&&);
+ const D operator()(const int&&);
+} f;
+
+std::optional<int> o;
+const auto& co = o;
+
+auto o1 = o.transform(f);
+static_assert(std::is_same_v<decltype(o1), std::optional<A>>);
+
+auto o2 = co.transform(f);
+static_assert(std::is_same_v<decltype(o2), std::optional<B>>);
+
+auto o3 = std::move(o).transform(f);
+static_assert(std::is_same_v<decltype(o3), std::optional<C>>);
+
+auto o4 = std::move(co).transform(f);
+static_assert(std::is_same_v<decltype(o4), std::optional<D>>);