fork(2) download
  1. #include <iostream>
  2. #include <tuple>
  3.  
  4. template <typename T, typename Tuple>
  5. auto push_front(const T& t, const Tuple& tuple)
  6. {
  7. return std::tuple_cat(std::make_tuple(t), tuple);
  8. }
  9.  
  10. template <typename Tuple, std::size_t ... Is>
  11. auto pop_front_impl(const Tuple& tuple, std::index_sequence<Is...>)
  12. {
  13. return std::make_tuple(std::get<1 + Is>(tuple)...);
  14. }
  15.  
  16. template <typename Tuple>
  17. auto pop_front(const Tuple& tuple)
  18. {
  19. return pop_front_impl(tuple,
  20. std::make_index_sequence<std::tuple_size<Tuple>::value - 1>());
  21. }
  22.  
  23. int main()
  24. {
  25. std::tuple<char> tc{'*'};
  26.  
  27. std::tuple<int, char> tic = push_front(42, tc);
  28. std::tuple<char> tc2 = pop_front(tic);
  29. std::cout << (tc == tc2) << std::endl;
  30. }
  31.  
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
1