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?