I was looking at this page about "new" features of C++17. In particular I understand almost all of the following code:
#include <iostream>
#include <variant>
struct Fluid { };
struct LightItem { };
struct HeavyItem { };
struct FragileItem { };
template<class... Ts> struct overload : Ts... { using Ts::operator()...; };
template<class... Ts> overload(Ts...) -> overload<Ts...>;
int main() {
std::variant<Fluid, LightItem, HeavyItem, FragileItem> package;
std::visit(overload{
[](Fluid& ) { std::cout << "fluid\n"; },
[](LightItem& ) { std::cout << "light item\n"; },
[](HeavyItem& ) { std::cout << "heavy item\n"; },
[](FragileItem& ) { std::cout << "fragile\n"; }
}, package);
}
What I do not understand is the
using Ts::operator()...;
inside de definition of struct overload. To my knowledge such use of using keyword is to ensure operator() to be public. But it seems to me already public, as far as lambdas are involved. So I would say it is redundant. I try to compile and execute with just
template<class... Ts> struct overload : Ts... { };
and everything works fine. Am I wrong? Am I missing something?