[PATCH] Implement std::visit<R> for C++2a (P0655R1)
Ville Voutilainen
ville.voutilainen@gmail.com
Sat Apr 6 00:07:00 GMT 2019
On Sat, 6 Apr 2019 at 02:55, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> 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.
Okay, I merged that with the original. I also renamed the neg-test, so
here goes the hopefully final variant change for GCC 9:
2019-04-06 Ville Voutilainen <ville.voutilainen@gmail.com>
Fix visit<R> for variant.
* include/std/variant (__do_visit): Add a template parameter
for enforcing same return types for visit.
(__gen_vtable_impl): Likewise.
(_S_apply_single_alt): Adjust.
(__visit_invoke_impl): New. Handle casting to void.
(__do_visit_invoke): New. Enforces same return types.
(__do_visit_invoke_r): New. Converts return types.
(__visit_invoke): Adjust.
(__gen_vtable): Add a template parameter for enforcing
same return types for visit.
* testsuite/20_util/variant/visit_r.cc: Add a test for a visitor with
different return types.
* testsuite/20_util/variant/visit_neg.cc: New. Ensures that
visitors with different return types don't accidentally
compile with regular visitation.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: variant-visit_r_5.diff
Type: text/x-patch
Size: 8880 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20190406/e9331590/attachment.bin>
More information about the Libstdc++
mailing list