fork(3) download
  1. #include <functional>
  2. #include <iostream>
  3. #include <tuple>
  4. #include <type_traits>
  5. #include <utility>
  6. #include <experimental/tuple>
  7.  
  8. using namespace std;
  9.  
  10. namespace detail {
  11. template<class F, class...Args>
  12. void for_each_arg(F&& f, Args&&...args) {
  13. using detail = int[];
  14.  
  15. static_cast<void>(detail{((f(std::forward<Args>(args))), void(), 0)..., 0});
  16. }
  17. }
  18.  
  19. template <typename F, typename Tuple>
  20. void for_each_tuple_element(F&& f, Tuple&& t) {
  21. return experimental::apply([&](auto&&...args) { detail::for_each_arg(forward<F>(f), decltype(args)(args)... ); }, forward<Tuple>(t));
  22. }
  23.  
  24. int main(){
  25. for_each_tuple_element([](const auto& i){cout << i << ' ';}, make_tuple(3.14, "hello", -1));
  26. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
3.14 hello -1