fork download
  1. #include <iostream>
  2. struct parser {
  3. template <typename... T>
  4. parser(std::string head, T... tail) {
  5. add_options(std::move(head), std::forward<T>(tail)...);
  6. }
  7.  
  8. // Base case
  9. void add_options(std::string head) {
  10. std::cout << "option: " << head.c_str() << "\n";
  11. }
  12.  
  13. // Recursive case
  14. template <typename T0, typename... Ts>
  15. void add_options(std::string head, T0&& t0, Ts&&... ts) {
  16. add_options(std::move(head));
  17. add_options(std::forward<T0>(t0), std::forward<Ts>(ts)...);
  18. }
  19. };
  20.  
  21. int main() {
  22. parser parse("hello", "world");
  23. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
option: hello
option: world