fork(1) download
  1. #include <tuple>
  2. #include <utility>
  3.  
  4. template<std::size_t I = 0, typename FuncT, typename... Tp>
  5. inline typename std::enable_if<I == sizeof...(Tp), void>::type
  6. for_each(std::tuple<Tp...> &, FuncT) // Unused arguments are given no names.
  7. { }
  8.  
  9. template<std::size_t I = 0, typename FuncT, typename... Tp>
  10. inline typename std::enable_if<I < sizeof...(Tp), void>::type
  11. for_each(std::tuple<Tp...>& t, FuncT f)
  12. {
  13. f(std::get<I>(t));
  14. for_each<I + 1, FuncT, Tp...>(t, f);
  15. }
  16.  
  17. struct Window{
  18. void show(){}
  19. //stuff
  20. }w1, w2, w3;
  21.  
  22. struct Widget{
  23. void show(){}
  24. //stuff
  25. }w4, w5, w6;
  26.  
  27. struct Toolbar{
  28. void show(){}
  29. //stuff
  30. }t1, t2, t3;
  31.  
  32. int main() {
  33. auto t = std::make_tuple(w3, w4, w5, t1);
  34. for_each(t, [](auto &obj){
  35. obj.show();
  36. });
  37. }
  38.  
Success #stdin #stdout 0s 3452KB
stdin
Standard input is empty
stdout
Standard output is empty