#include <iostream>
#include <tuple>
#include <vector>
class Stream
{
public:
template<class T> Stream& operator>>(T &t)
{
t.Serialize(*this);
return *this;
}
template<class T> Stream& operator&(T &t)
{
*this >> t;
return *this;
}
private:
};
template<class T> Stream& operator>>(Stream &stream, std::vector<T>& vec)
{
T t;
stream >> t;
vec.push_back(std::move(t));
}
template<std::size_t I, std::size_t S, class ... T> class TupleRecv
{
public:
void inline operator()(Stream& stream, std::tuple<T ...>& tuple)
{
stream >> std::get<I>(tuple);
TupleRecv<I + 1, S, T ...>()(stream, tuple);
}
private:
};
template<std::size_t S, class ... T> class TupleRecv<S, S, T ...>
{
public:
void inline operator()(Stream&, std::tuple<T ...>&)
{
}
private:
};
template<class ... T> Stream& operator>>(Stream &stream, std::tuple<T ...>& tuple)
{
TupleRecv<0, std::tuple_size<std::tuple<T ...>>::value, T ...>()(stream, tuple);
return stream;
}
Stream& operator>>(Stream& stream, int& i)
{
// do i
i = 9;
return stream;
}
Stream& operator>>(Stream& stream, char& c)
{
// do c
c = 'a';
return stream;
}
int main(int,char**)
{
Stream s;
std::vector<std::tuple<int, char>> data;
s >> data;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHVwbGU+CiNpbmNsdWRlIDx2ZWN0b3I+CgpjbGFzcyBTdHJlYW0KewpwdWJsaWM6CiAgICB0ZW1wbGF0ZTxjbGFzcyBUPiBTdHJlYW0mIG9wZXJhdG9yPj4oVCAmdCkKCXsKCQl0LlNlcmlhbGl6ZSgqdGhpcyk7CgkJcmV0dXJuICp0aGlzOwoJfQoKCXRlbXBsYXRlPGNsYXNzIFQ+IFN0cmVhbSYgb3BlcmF0b3ImKFQgJnQpCgl7CgkJKnRoaXMgPj4gdDsKCQlyZXR1cm4gKnRoaXM7Cgl9CnByaXZhdGU6Cn07Cgp0ZW1wbGF0ZTxjbGFzcyBUPiBTdHJlYW0mIG9wZXJhdG9yPj4oU3RyZWFtICZzdHJlYW0sIHN0ZDo6dmVjdG9yP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