fork download
  1. #include <iostream>
  2. #include <tuple>
  3. #include <vector>
  4.  
  5. struct Stream
  6. {
  7. template<class T> Stream& operator>>(T& t) {
  8. t.Serialize(*this);
  9. return *this;
  10. }
  11.  
  12. template<class T> Stream& operator&(T& t) {
  13. *this >> t;
  14. return *this;
  15. }
  16. };
  17.  
  18. template<class T> Stream& operator>>(Stream& stream, std::vector<T>& vec) {
  19. T t;
  20. stream >> t;
  21. vec.push_back(std::move(t));
  22. return stream;
  23. }
  24.  
  25. template<std::size_t I, std::size_t S, class ... T> struct TupleRecv {
  26. void inline operator()(Stream& stream, std::tuple<T ...>& tuple) {
  27. stream >> std::get<I>(tuple);
  28. TupleRecv<I + 1, S, T ...>()(stream, tuple);
  29. }
  30. };
  31.  
  32. template<std::size_t S, class ... T> struct TupleRecv<S, S, T ...> {
  33. void inline operator()(Stream&, std::tuple<T ...>&) {}
  34. };
  35.  
  36. template<class ... T> Stream& operator>>(Stream& stream, std::tuple<T ...>& tuple) {
  37. TupleRecv<0, std::tuple_size<std::tuple<T ...>>::value, T ...>()(stream, tuple);
  38. return stream;
  39. }
  40.  
  41. Stream& operator>>(Stream& stream, int& i) {
  42. // do i
  43. i = 9;
  44. return stream;
  45. }
  46.  
  47. int main(int,char**) {
  48. Stream s;
  49. std::vector<std::tuple<int>> data;
  50. s >> data;
  51. return 0;
  52. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Standard output is empty