Advertisement
fenixD3

print tuple

May 16th, 2023
784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <iterator>
  4. #include <tuple>
  5.  
  6. using test_tuple_type = std::tuple<int, int, std::string>;
  7.  
  8. std::ostream& operator<<(std::ostream& out, const test_tuple_type& value)
  9. {
  10.     out << std::get<2>(value) << ',' << std::get<0>(value) << ',' << std::get<1>(value);
  11.     return out;
  12. }
  13.  
  14. template <typename TCont>
  15. void print(const TCont& s, std::string delim = " ")
  16. {
  17.     std::copy(s.begin(), s.end(), std::ostream_iterator<typename TCont::value_type>(std::cout, delim.c_str()));
  18.     std::cout << std::endl;
  19. }
  20.  
  21. int main()
  22. {
  23.     std::vector<test_tuple_type> v = {
  24.         {1, 2, "hop"},
  25.         {3, 4, "hey"},
  26.         {5, 6, "la-la-ley"},
  27.     };
  28.  
  29.     print(v);
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement