C++Guns – RoboBlog


C++ Guns: apply generic lambda to tuple

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

Part 1: print std::array with std::integer_sequence
Part 2: convert tuple to parameter pack
Part 3: print std::array with std::apply and fold
Part 4: fold over std::tuple und erzeugten Assembler Code
Part 5: fold over std::tuple of std::vector of Types ...
Part 6: apply generic lambda to tuple
Part 7: Play with std::tuple and std::apply

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