1

I am having trouble using the variant visitation overload trick described here in gcc. I tried different versions on compiler explorer and none of them works. On the other hand the newest clang versions accept it.

template <class... Fs>
struct overload : Fs...
{
    template <class... Ts>
    overload(Ts&& ...ts) : Fs{std::forward<Ts>(ts)}... {}

    using Fs::operator()...;
};

template <class... Ts>
overload(Ts&&...) -> overload<std::remove_reference_t<Ts>...>;


int main()
{
    auto visitor = overload(
        [](int) { },
        [](double) { }
    );
}

gives

<source>: In instantiation of 'overload<Fs>::overload(Ts&& ...) [with Ts = {func()::<lambda(int)>, func()::<lambda(double)>}; Fs = {}]':
<source>:21:13:   required from here
<source>:7:52: error: mismatched argument pack lengths while expanding 'Fs'

     overload(Ts&& ...ts) : Fs{std::forward<Ts>(ts)}...
                                                    ^~~
Compiler returned: 1

it seems that gcc is having trouble with the template deduction guide.

EDIT: I found that replacing the deduction guide by a function template like this

template <class... Ts>
overload<std::remove_reference_t<Ts>...> overloaded(Ts&& ...ts)
{
    return overload<std::remove_reference_t<Ts>...>(ts...);
}

works, but I would be interested if there is a problem with the deduction guides or if it is a gcc bug?

Barry
  • 286,269
  • 29
  • 621
  • 977
user26756
  • 233
  • 1
  • 9
  • 1
    According a comment in the page you link, it's a g++ bug. – max66 Oct 21 '18 at 19:29
  • Thanks I must have overlooked that. I suspect that the comment is refering to this gcc issue https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80438 – user26756 Oct 21 '18 at 19:46
  • I suppose you're right; if it isn't the correct bug, is another very very similar and, presumably, related. – max66 Oct 21 '18 at 19:51

0 Answers0