[v3 PATCH] Use single-visitation in variant assignment and swap.

Ville Voutilainen ville.voutilainen@gmail.com
Mon Apr 1 08:50:00 GMT 2019


On Mon, 1 Apr 2019 at 11:45, Paolo Carlini <paolo.carlini@oracle.com> wrote:
> >>> +    __visitor_result_type(_Visitor&& __visitor, _Variants&&... __variants)
> >>> +    {
> >>> +      if constexpr(__use_index)
> >>> +        return __detail::__variant::__variant_idx_cookie{};
> >>> +      else
> >>> +     return std::forward<_Visitor>(__visitor)(
> >> If I'm not misreading something, the new function will be usually
> >> compiled/optimized to something very small and isn't constexpr thus
> >> normally should be explicitly marked inline. Or the problem is the
> >> missing constexpr? (sorry, I didn't really study the new code)
> > The only use of this function is to compute its return type. It's
> > never called. I should probably comment on that...
>
> Oh, yes, now I see, a few lines below. That's clear enough, I think.

It's a bit novel, but happens to be much easier to write than
something using std::conditional or
some such. Traits like that may end up evaluating their template
arguments much sooner than
I'd like, but shoving it into a helper function with an if-constexpr
in it makes it trivial and I don't
need to worry about the validity of the branch taken, since it's not
instantiated. This is a new
use case for if-constexpr even for me, but it's a very nice bonus
ability in that already shining-fabulous
language facility. :)



More information about the Gcc-patches mailing list