Overloading multiple function objects by reference
In C++17, it is trivial to implement an overload(fs...) function that, given any number of arguments fs... satisfying FunctionObject , returns a new function object that behaves like an overload of fs... . Example: template <typename... Ts> struct overloader : Ts... { template <typename... TArgs> overloader(TArgs&&... xs) : Ts{forward<TArgs>(xs)}... { } using Ts::operator()...; }; template <typename... Ts> auto overload(Ts&&... xs) { return overloader<decay_t<Ts>...>{forward<Ts>(xs)...}; } int main() { auto o = overload([](char){ cout << "CHAR"; }, [](int) { cout << "INT"; }); o('a'); //