fork(1) download
  1. #include <vector>
  2. #include <typeinfo>
  3. #include <random>
  4. #include <chrono>
  5. #include <iostream>
  6.  
  7. int give_me_anumber() {
  8. static std::default_random_engine rnd_engine(
  9. std::chrono::system_clock::now().time_since_epoch().count());
  10. std::uniform_int_distribution<> rnd_value(0, 1);
  11. return rnd_value(rnd_engine);
  12. }
  13.  
  14. template<typename A, typename B>
  15. void foo(const std::vector<A>& va,
  16. const std::vector<B>& vb) {
  17. std::cout << "-----The end of recursion-----\n"
  18. "Type VectorA: " << typeid(A).name() << "\n"
  19. "Type VectorB: " << typeid(B).name() << "\n"
  20. "----------------------------------------\n";
  21. }
  22.  
  23. template<typename... Args>
  24. void foo(std::string str, Args... args) {
  25. int number = give_me_anumber();
  26. if (number == 0) {
  27. std::vector<int> vector;
  28. foo(args..., vector);
  29. } else if (number == 1) {
  30. std::vector<double> vector;
  31. foo(args..., vector);
  32. }
  33. }
  34.  
  35. int main(int argc, char *argv[]) {
  36. foo("file1", "file2");
  37. return 0;
  38. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
-----The end of recursion-----
Type VectorA: i
Type VectorB: i
----------------------------------------