So this example from: http://en.cppreference.com/w/cpp/utility/variant/visit declares the specialized type:
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
Which is constructed as an r-value here:
std::visit(overloaded {
[](auto arg) { std::cout << arg << ' '; },
[](double arg) { std::cout << std::fixed << arg << ' '; },
[](const std::string& arg) { std::cout << std::quoted(arg) << ' '; },
}, v);
I'm trying to figure out how this works. What is the type that overloaded
inherits from here? It seems like an array of lambdas but I don't see how that would have an operator()
. Can someone explain how the inheritance is working here?