C++Guns – RoboBlog


C++ Guns: apply generic lambda to tuple

Filed under: Allgemein — Tags: — Thomas @ 13:07

Hm, generic lambdas sind toll.

template<typename...Args, typename Func>
auto func(const std::tuple<Args...>& t, Func p) {     
    auto f = [&p](const auto&...x){ (p(x), ...); };
    std::apply(f, t);

auto func2(const std::tuple<int,double>& t) {
    auto print_dat_shiat = [](const auto& p) { std::cout << typeid(p).name() << std::endl; };     
    func(t, print_dat_shiat);

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress