/*
That's how operator<< and >> should've been overloaded.
Alexandr Poltavsky
*/
#include <vector>
#include <iostream>
template<class T0, class T1> auto& operator<<( std::vector<T0>& vec, T1&& value ) {
vec.push_back( std::forward<T1>( value ) );
return vec;
}
template<class T0, class T1> auto& operator>>( std::vector<T0>& vec, T1& value ) {
value = vec.back();
vec.pop_back();
return vec;
}
int main() {
std::vector<int> v{1,2,3};
int i{};
for(auto i : v) std::cout << i <<" ";
std::cout << std::endl;
v << 4 << 5;
for(auto i : v) std::cout << i <<" ";
std::cout << std::endl;
v >> i;
std::cout << "i = " << i << std::endl;
for(auto i : v) std::cout << i <<" ";
std::cout << std::endl;
}
LyoKICBUaGF0J3MgaG93IG9wZXJhdG9yPDwgYW5kID4+IHNob3VsZCd2ZSBiZWVuIG92ZXJsb2FkZWQuIAogIEFsZXhhbmRyIFBvbHRhdnNreQoqLwoKI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKdGVtcGxhdGU8Y2xhc3MgVDAsIGNsYXNzIFQxPiBhdXRvJiBvcGVyYXRvcjw8KCBzdGQ6OnZlY3RvcjxUMD4mIHZlYywgVDEmJiB2YWx1ZSApIHsKCXZlYy5wdXNoX2JhY2soIHN0ZDo6Zm9yd2FyZDxUMT4oIHZhbHVlICkgKTsKCXJldHVybiB2ZWM7Cn0KCnRlbXBsYXRlPGNsYXNzIFQwLCBjbGFzcyBUMT4gYXV0byYgb3BlcmF0b3I+Piggc3RkOjp2ZWN0b3I8VDA+JiB2ZWMsIFQxJiB2YWx1ZSApIHsKCXZhbHVlID0gdmVjLmJhY2soKTsKCXZlYy5wb3BfYmFjaygpOwoJcmV0dXJuIHZlYzsKfQoKaW50IG1haW4oKSB7CgoJc3RkOjp2ZWN0b3I8aW50PiB2ezEsMiwzfTsKCWludCBpe307IAoJCglmb3IoYXV0byBpIDogdikgc3RkOjpjb3V0IDw8IGkgPDwiICI7CglzdGQ6OmNvdXQgPDwgc3RkOjplbmRsOwoKCX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