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

Ville Voutilainen ville.voutilainen@gmail.com
Fri Apr 5 22:55:00 GMT 2019


On Fri, 5 Apr 2019 at 23:29, Jonathan Wakely <jwakely@redhat.com> wrote:
>
> On 05/04/19 19:06 +0100, Jonathan Wakely wrote:
> >       * doc/xml/manual/status_cxx2020.xml: Update status.
> >       * include/std/variant (visit<R>): Define for C++2a (P0655R1).
> >       * testsuite/20_util/variant/visit_r.cc: New test.
>
> This implementation is wrong, the conversions to R need to happen for
> each possible invocation, which makes it more complicated (we need to
> duplicate some code). I'll fix it next week.

Deep sigh. I wanted to postpone this feature until next stage1, but
now that you have sent soldiers
to Mirkwood, brace yourself for The Elf. :) Tested on Linux-x64, OK for trunk?

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_r_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.diff
Type: text/x-patch
Size: 8711 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20190405/9de0d40e/attachment.bin>


More information about the Libstdc++ mailing list