fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <utility>
  4. #include <vector>
  5. using std::next;
  6. template<typename Iter, typename Func, typename...Funcs>
  7. void RotateHandlers(Iter b, Iter e, Func f, Funcs...fs) {
  8. if (b != e) {
  9. f(*b);
  10. RotateHandlers(next(b), e, fs..., f);
  11. }
  12. }
  13.  
  14. int main() {
  15. std::vector<std::string> v({"Hello", "world", "it's", "really", "great", "to", "be", "here"});
  16. RotateHandlers(v.begin(), v.end(),
  17. [](const std::string& s){std::cout << "First|" << s << std::endl;},
  18. [](const std::string& s){std::cout << "Then |" << s << std::endl;},
  19. [](const std::string& s){std::cout << "And |" << s << std::endl
  20. << " |" << std::string(s.size(), '-') << std::endl;}
  21. );
  22. return 0;
  23. }
Success #stdin #stdout 0s 3020KB
stdin
Standard input is empty
stdout
First|Hello
Then |world
And  |it's
     |----
First|really
Then |great
And  |to
     |--
First|be
Then |here