template<typename... Functors>
struct qxFuncAggregate< Functors >
A template struct that takes an arbitrary number of functors as arguments and, when instantiated, produces a struct with all operator()
overloads from all provided functors.
This helper struct is commonly used in the std::variant
overload visit pattern to concisely implement a handler for all alternatives:
#include <iostream>
#include <string>
#include <variant>
#include <vector>
#include <functional>
using var_t = std::variant<int, long, float, double, bool, char, std::string>;
void freeFunc(char arg) { std::cout << arg << " (from wrapped char free function)"; }
int main()
{
std::vector<var_t> vec = {10, 15l, 3.7f, 1.5, true, 'c', "hello"};
auto f = [](std::string arg) { std::cout << arg << " (from string named lambda)"; };
for (auto& v : vec)
{
[](auto arg) { std::cout << arg << " (from catch-all lambda)"; },
[](float arg) { std::cout << arg << " (from float lambda)"; },
[](double arg) { std::cout << std::fixed << arg << " (from double lambda)"; },
[](bool arg) { std::cout << arg << " (from bool lambda)"; },
std::function(freeFunc),
f
}, v);
std::cout << std::endl;
}
}