[PATCH] Implement std::visit<R> for C++2a (P0655R1)

Ville Voutilainen ville.voutilainen@gmail.com
Fri Apr 5 23:56:00 GMT 2019


On Sat, 6 Apr 2019 at 02:48, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> and
>
> -      return __do_visit<false, false>(std::forward<_Visitor>(__visitor),
> -                      std::forward<_Variants>(__variants)...);
> +      return (_Res)
> +    __do_visit<false, false>(std::forward<_Visitor>(__visitor),
> +                 std::forward<_Variants>(__variants)...);
>
> and the visit_r test is amended to also test visitation of a visitor
> with a const void result, when the visitor
> itself does not return void.

Just in case that cast looks scary: the implicit conversion is also
deep down in __visit_invoke, so
we do actually require implicit convertibility as we are supposed to.
If that's still too scary,
we can just do

-      return (_Res)
+      if constexpr (!is_void_v<_Res>)
+        return
+         __do_visit<false, false>(std::forward<_Visitor>(__visitor),
+                                  std::forward<_Variants>(__variants)...);
+      else

like in the attached patch.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: variant-visit_r_4.diff
Type: text/x-patch
Size: 8919 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20190405/5766437e/attachment.bin>


More information about the Gcc-patches mailing list