#include <iostream>
#include<vector>
using namespace std;
template <class T> class vector_inserter{
public:
std::vector<T> v;
vector_inserter(std::vector<T>& v):v(v){}
vector_inserter& operator,(const T& val){v.push_back(val);return *this;}
};
template <class T> vector_inserter<T> operator+=(std::vector<T>& v,const T& x)
{
return vector_inserter<T>(v),x;
}
int main()
{
vector_inserter<int> t+=1,2,3,
}
I came across this code in stack overflow, i am still trying to understand how it works, i try to compile the above code but i get errors as expected initializer be +=
Is there any good way to overload operators for Vector operation like {}, (), +=?