fork download
  1. #include <iostream>
  2. #include <tuple>
  3. #include <vector>
  4.  
  5. class Stream
  6. {
  7. public:
  8. template<class T> Stream& operator>>(T &t)
  9. {
  10. t.Serialize(*this);
  11. return *this;
  12. }
  13.  
  14. template<class T> Stream& operator&(T &t)
  15. {
  16. *this >> t;
  17. return *this;
  18. }
  19. private:
  20. };
  21.  
  22. template<class T> Stream& operator>>(Stream &stream, std::vector<T>& vec)
  23. {
  24. T t;
  25. stream >> t;
  26. vec.push_back(std::move(t));
  27. }
  28.  
  29. template<std::size_t I, std::size_t S, class ... T> class TupleRecv
  30. {
  31. public:
  32. void inline operator()(Stream& stream, std::tuple<T ...>& tuple)
  33. {
  34. stream >> std::get<I>(tuple);
  35. TupleRecv<I + 1, S, T ...>()(stream, tuple);
  36. }
  37. private:
  38. };
  39.  
  40. template<std::size_t S, class ... T> class TupleRecv<S, S, T ...>
  41. {
  42. public:
  43. void inline operator()(Stream&, std::tuple<T ...>&)
  44. {
  45. }
  46. private:
  47. };
  48.  
  49. template<class ... T> Stream& operator>>(Stream &stream, std::tuple<T ...>& tuple)
  50. {
  51. TupleRecv<0, std::tuple_size<std::tuple<T ...>>::value, T ...>()(stream, tuple);
  52. return stream;
  53. }
  54.  
  55. Stream& operator>>(Stream& stream, int& i)
  56. {
  57. // do i
  58. i = 9;
  59. return stream;
  60. }
  61.  
  62. Stream& operator>>(Stream& stream, char& c)
  63. {
  64. // do c
  65. c = 'a';
  66. return stream;
  67. }
  68.  
  69. int main(int,char**)
  70. {
  71. Stream s;
  72. std::vector<std::tuple<int, char>> data;
  73. s >> data;
  74. return 0;
  75. }
Success #stdin #stdout 0s 3424KB
stdin
Standard input is empty
stdout
Standard output is empty