fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <tuple>
  4. using namespace std;
  5.  
  6. template<typename T, T ...ts>
  7. struct value_list
  8. {
  9. //Get individual value
  10. template<int ix>
  11. static constexpr auto get()
  12. { return std::get<ix>(std::make_tuple(ts...)); }
  13.  
  14. //Get a container
  15. template<typename Container>
  16. static auto get_container() {return Container{ts...};}
  17.  
  18. template<T new_val>
  19. constexpr auto push_back()
  20. {return value_list<T, ts..., new_val>();}
  21.  
  22. template<T new_val>
  23. constexpr auto push_front()
  24. {return value_list<T, new_val, ts...>();}
  25. };
  26.  
  27. int main() {
  28. value_list<int, 5, 4, 12> vl;
  29. std::cout << vl.get<1>() << std::endl;
  30.  
  31. auto v2 = vl.push_back<33>();
  32. std::cout << v2.get<3>() << std::endl;
  33.  
  34. for(auto val : v2.get_container<std::vector<int>>())
  35. std::cout << val << " ";
  36.  
  37. std::cout << std::endl;
  38.  
  39. // your code goes here
  40. return 0;
  41. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
4
33
5 4 12 33